I want that my Jenkins job will be triggered by commits to each one of my branches in my github repo.
I have a GitHub repo with this webhook to my Jenkins with this payload URL:
http://<my-jenkins-ip>:8080/github-webhook/
the payload delivery status is 200 OK.
In my Jenkins server, I have a pipeline job that declared like this:
pipeline {
agent {
label 'master'
}
stages {
stage('scm') {
steps {
dir("$WORKSPACE/azure-voting-app-redis") {
git 'https://github.com/einavle/azure-voting-app-redis'
}
}
}
}
In the job 'Build trigger section' I'm checking the "GitHub hook trigger for GITScm polling"
I'm expecting the job to be triggered on each commit to any of the branches in my Github repo. But the actual behavior is that the job is triggered only by commits to the master branch.
I'm asking:
- How do I configure the job to be triggered by commits to any of the branches?
- How can I fetch the branch name of the last commit (that triggered the job)?
the answer to 1 is: instead of
git 'https://github.com/einavle/azure-voting-app-redis'
use:git branch: '**', url: 'https://github.com/einavle/azure-voting-app-redis'
The answer to 2 is to use
git rev-parse --abbrev-ref HEAD
to take the triggering branch name