Trigger Jenkins Job only when changes happen to a particular branch

寵の児 提交于 2021-01-28 03:01:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!