Scenario / Questions
I’d like to configure a single Jenkins build (“job”) which will both:
- watch for new branches and build them when they appear
- 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?
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.
Find below all possible solutions or suggestions for the above questions..
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.)
I was in the same shoes, enabling ‘Force polling using workspace’ would fix issues.jenkins-ci.org/browse/JENKINS-29896
Disclaimer: This has been sourced from a third party syndicated feed through internet. We are not responsibility or liability for its dependability, trustworthiness, reliability and data of the text. We reserves the sole right to alter, delete or remove (without notice) the content in its absolute discretion for any reason whatsoever.