Only trigger Jenkins Pipeline job on commit to master

时光毁灭记忆、已成空白 提交于 2019-12-11 18:15:47

问题


I have a Jenkins Pipeline job which is triggered of a github webhook, so on a commit to Github the build gets triggered. However, I only want the build to be triggered when a commit is made to the master branch. Currently any commit triggers a build even if the commit is made on a feature branch.

Is there any way to achieve this without resorting to a multibranch job?

I can't see any way to filter on branch (for the trigger) in the Jenkins config, the jenkinsfile or in the Github repo's webhook.

The only branch specific information I can find is which branch the code will build from but a commit to any other branch will still 'trigger' a build.

Can anyone help?


回答1:


So the more I looked into this, the more i realised that Stephen was right and I should be using the multibranch pipeline approach. Indeed, in the newer Blue Ocean UI, all pipelines are multibranch by default, further suggesting this is the way to go.

As to the second issue around triggering the build, this did seem to be related to the branch source that has been set up. This was originally using the git branch source. Once this was changed to a github branch source and the github server configured correctly in jenkins then the trigger worked as expected.



来源:https://stackoverflow.com/questions/51102914/only-trigger-jenkins-pipeline-job-on-commit-to-master

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