Reputation: 555
I have a Jenkins job that builds branches that match "origin/feature/**".
Bitbucket triggers the job to build whenever there are changes to the repository via a repository hook (https://confluence.atlassian.com/display/BITBUCKET/Jenkins+hook+management).
This works fine whenever there is a change on a feature branch, the job recognizes that the branch has changed and builds it.
However, when there is a commit to a non-feature branch (eg. a merge to develop or master) bitbucket still triggers the job. There are no changes to any of the feature branches so it just builds the last built feature branch again.
Is there a way to control this?
Upvotes: 12
Views: 12142
Reputation: 3500
You can do that with Generic Webhook Trigger Plugin.
reference
.$reference
and the filter regexp set to ^(refs/heads/feature/.+)$
Upvotes: 0
Reputation: 1
Since i can not answer the comment top (whyever)
"you are correct but I want to do in jenkins pipeline job"
To let a pipeline-job build automatically after a push (per hook) i created another job that is configured just to be triggered by the bitbucket/git and has a follow-up job that points to the pipeline-job in the post-build-action. That was the only way i could manage this
Upvotes: 0
Reputation: 2062
After some research I found a good solution finally:
https://YOUR.JENKINS.SERVER:PORT/bitbucket-hook/
By this way I have three build projects, one for all features, one for develop and one for release branch.
Upvotes: 8
Reputation: 2254
The answer was in the comments section you linked to. Bitbucket will always call the hook to your job.
You need a proxy in front of Jenkins to segregate out posts.
https://github.com/oveddan/gitBuildForwarder
If this was SVN, I would tell you how to alter the SVN hook to only selectively trigger the hook based on Regex filtering.
Upvotes: 0