问题
I have configured a jenkins job and I wish it should be triggered when I make some changes to the Github for that particular branch.
I use the Github plugin and has enabled "build when a change is pushed to github".
But this option is triggering my Job if someone else create a separate branch and push to that branch.
Let me explain it below:
Change pushed to branch "release"
Jenkins notified and job executes - Expected behavior
Another change is now pushed to branch "xyz" but I don't intend this to cause execution of my Jenkins job. The Job "xyz" is created out of the same repo though.
How can I prevent changes pushed to other branches triggering my job?
Is enabling "build when a change is pushed to github" is not correct?
回答1:
In the git section of the job configuration is a field 'Branches to build'. You can specify here which branches will trigger a build when new commits are pushed to them.
e.g. for one of my jobs I have **/BARE-* , so only branches which start with BARE- will trigger a build.
回答2:
Read about github webhooks and add hook, in your hook check the name of the branch which is being pushed.
based upon the branch name decide what you want to do (build or not)
here you can read about the push event,
and here you can read about on how to write and use github hooks.
来源:https://stackoverflow.com/questions/30349418/trigger-jenkins-job-only-when-changes-happen-to-a-particular-branch