Reputation: 341
I am using job DSL plugin to create a jenkins multibranch pipeline job.
The generated job will not match any branches of my git repo:
Checking branches...
Checking branch feature/xyz
Does not meet criteria
Checking branch main
Does not meet criteria
Checking branch release/1.0.0
Does not meet criteria
When I open the configuration of the generated job and then click "save" (without making any changes) the repo is scanned again and this time the branches will match:
Checking branches...
Checking branch feature/xyz
Met criteria
Checking branch main
Met criteria
Checking branch release/1.0.0
Met criteria
When I look at the config.xml file for the original vs "saved" job the difference appears to be the following:
Original config.xml (via job dsl)
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList">
Updated config.xml (after saving unmodified configuration)
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="[email protected]_8ea_8a_724">
That is, the config.xml originally created via job DSL plugin did not have a 'plugin' attribute, but "saving" an unmodified config is re-written by jenkins and a 'plugin' attribute is added.
I'm not sure why re-writing the job config (without any actual changes) would fix a branch scanning issue. Is there a plugin issue here? Do I need to tweak my job DSL to specify a particular plugin? And if so, how?
Using:
Upvotes: 0
Views: 241
Reputation: 341
Found the solution.
The DSL included the following:
factory {
remoteJenkinsFileWorkflowBranchProjectFactory {
remoteJenkinsFileSCM {
gitSCM { ...
I had not specified a path to the Jenkinsfile for this remote SCM, as the documentation mentioned the following:
Relative location within the checkout of your Pipeline script. Note that it will always be run inside a Groovy sandbox. Default is Jenkinsfile if left empty.
That bit about the default value was not correct. I had to manually specify the path, even though I was using the default value:
factory {
remoteJenkinsFileWorkflowBranchProjectFactory {
remoteJenkinsFile 'Jenkinsfile'
remoteJenkinsFileSCM {
gitSCM { ...
Now the generated job from the DSL will recognize branches. Huzzah!
Upvotes: 0