Reputation: 365
I have a Github project with many branches.
Example
master
staging
feature-1
feature-2
I have a Jenkins job that has the "Poll SCM" option enabled with the following cronjob (10 7,9,11,13,15,17,19 * * 1-5)
However, this job will kick off when a change is made to master also.
I want a Jenkins job to only kick off if a commit to the staging branch.
Here is an output of the polling logs
Started on Nov 20, 2018 1:10:00 PM
no polling baseline in /var/jenkins_workspace/workspace/Staging-ALL-Deploy@libs/jenkins-pipeline-global-lib on
Using strategy: Default
[poll] Last Built Revision: Revision efccc8e212470802d64537e0a5e710f9b5c063b6 (refs/remotes/origin/staging)
> git --version # timeout=10
> git ls-remote -h http://git.company.com/org/repo.git # timeout=10
Found 56 remote heads on http://git.company.com/org/repo.git
[poll] Latest remote head revision on refs/heads/staging is: efccc8e212470802d64537e0a5e710f9b5c063b6 - already built by 171
Using strategy: Default
[poll] Last Built Revision: Revision efccc8e212470802d64537e0a5e710f9b5c063b6 (refs/remotes/origin/staging)
> git --version # timeout=10
> git ls-remote -h http://git.company.com/org/repo.git # timeout=10
Found 56 remote heads on http://git.company.com/org/repo.git
[poll] Latest remote head revision on refs/heads/master is: 865459e59ef5f91fddbd7453d9f2205560327c44
Done. Took 0.46 sec
Changes found
Is this possible?
Thanks John
Upvotes: 5
Views: 10150
Reputation: 86
You can set which branch you want to build with following way:
Configure -> Source Code Management tab -> Branch to Build -> Branch specifier
just write staging in this section. Then go to Build Triggers tab, select GitHub hook trigger for GITScm polling.
Don't forget to add webhook <YOUR-JENKINS-URL>/github-webhook/
to your Github project and select sending push events as json.
With this way, you can create a build whenever a push made to a specific branch. With pooling, it will pull the repository with given time intervals, which is way more costly.
Upvotes: 2