Reputation: 361
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?
Upvotes: 2
Views: 7391
Reputation: 21
You can change the mode of which branch will 'trigger' a build by followed steps
Location: Jenkins --> new item --> pipeline --> build triggers --> advanced --> Allowed branches --> Filter branches by ***
Upvotes: 1
Reputation: 361
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.
Upvotes: 1