1

I am pretty new to Jenkins, and when I make a pull request, the Github webhook triggers a rebuild on all branches in the repo. However, I only want the branch associated with the pull request to be built. I suspect that all branches are built due to nothing specified in the "Branch specifier."

Is there a way to specify to build only the branch the pull request was made to?

Thanks!

Vicky
  • 11
  • 1
  • Saw https://stackoverflow.com/questions/27403576/build-only-the-git-branch-that-has-been-pushed-to/39884629#39884629, but origin/feature** did not work for me. It built all of the branches with feature in the prefix, not just the single branch with the change. – Vicky Jul 10 '20 at 21:37
  • Jenkins will build all "origin/feature*" branches until it has "marked" all as done. If you just want a particular branch, don't use any wildcards in the branch specifier. something like `origin/feature_xyz` or even `*/branch_xyzzy` – Tim Lum Jul 10 '20 at 23:52
  • 1
    Sorry if I wasn't clear, but I don't have a particular branch I want to build-- I'm just trying to build whichever branch has a change, so it could be "origin/feature_a", or "origin/feature_b", or "origin/feature_c", etc. For example, if "origin/feature_a" is changed, it should build that branch only and not the other feature branches. But, I don't think it makes sense to limit the specific to "origin/feature_a", since I want to build origin/feature_b as well if there's a change to that. – Vicky Jul 11 '20 at 04:25
  • When you make a new job with a branch specifier that has multiple matches, the first build trigger will cause Jenkins to iterate through all the matching branches until it "catches up". The webhook itself is just a generic build trigger that isn't specific to the commit hash that trigger it. Once it has caught up, the next trigger would be on the new commit filtered by the branch specifier. It won't rebuild the other other branches that it already marked as done. – Tim Lum Jul 12 '20 at 06:41

1 Answers1

0

To resolve your issue try to use multibranch pipeline job or use filter in simple pipeline job. To use multibranch pipeline job you need to install Pipeline: Multibranch plugin.

Pipeline job example

In simple pipeline job choose "Build when a change is pushed to GitLab" in "Build trigger" section -> Advanced -> Filter branches by name

Dmitriy Tarasevich
  • 1,082
  • 5
  • 6