I have a repository on GitHub with multiple branches, and I want to automate my builds.
I have the logic to build my branch using the Git List Branch plugin.
1
My problem is that I want to automatically build the branch that was just pushed. I just need to know the name of the branch, but that’s where I’m stuck—I don’t know what type of project I need or what the next step should be.
This is my jenkins file that im using to run a branch but my problem is how to automate the build of the branch that was just pushed
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: '------------'
}
}
stage('Get Branches') {
steps {
script {
def branches = bat(script: 'git ls-remote --heads ----------------', returnStdout: true).trim()
def branchList = branches.split('n').collect { it.split('/').last() }
branchList = branchList.drop(1)
echo "Branches found: ${branchList.join(', ')}"
branchList.each { branch ->
echo "Processing branch: ${branch}"
bat """
docker-compose build --build-arg BRANCH_NAME=${branch}
docker-compose up -d
docker exec -t tinyp-ci /bin/bash -c "run-tests.sh"
docker exec -t tinyp-ci /bin/bash -c "cd -------------------"
docker-compose down
"""
}
}
}
}
}
}
user26878866 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.