3

I'd like to configure a single Jenkins build ("job") which will both:

  1. watch for new branches and build them when they appear
  2. build a named branch or commit on request

I can achieve (1) by setting "Branches to build" to "**"

I can achieve (2) by making the build parameterised and setting "Branches to build" to "$branch" (like this tutorial)

Is there any way to do both at once?

Motivation

My use case for (1) is that I want "feature branches" to be tested prior to merging into master, so we can see at code review / pull request time whether the changes pass all tests.

My use case for (2) is that sometimes a build fails for a spurious reason (like a flaky test) and I want to re-run it, or perhaps an old branch has fallen off the bottom of the history and I want to re-run its tests.

2

If you have a parameterised build with no default value and also set your job to poll your source control under Build Triggers > Poll SCM then it should all work.

It is important that your branch parameter has no default value so that $branch is empty when the job is triggered from polling, because Branches to build interprets an empty value as meaning any branch.

(Note that this will build every commit, not just "new branches" as per (1), but so would any solution that sets Branches to build to ** as you suggest.)

1

I was in the same shoes, enabling 'Force polling using workspace' would fix issues.jenkins-ci.org/browse/JENKINS-29896

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.