-1

I use the job dsl to create multibranchPipelineJob jobs.

In my job dsl script I create some multibranchPipelineJobs. If I run the seed job, no matter if the config changed or not, it triggers a branch scan job for all the multibranchPipelineJobs. This must mean it's not idempotent and is just reapplying the config and saving it causing Jenkins to trigger scans for the jobs. Is this expected? Is there a way to have the job dsl check if there are changes first before just clobbering the whole thing every time?

I want to confirm the behavior I'm seeing is expected, or if I'm doing something wrong.

halfer
  • 19,824
  • 17
  • 99
  • 186
red888
  • 27,709
  • 55
  • 204
  • 392

2 Answers2

0

Normally, this is not the case, and DSL will not re-apply the configuration (I did not use DSL with multibranchPipelineJobs yet, though).

However, some plugins do silently modify the job configuation once a build has been performed. In those cases, running the DSL script will re-apply (ot rather: restore) the job configuration according to the DSL spec.

You can trace such cases with the "Job Configuration History" plugin. Silent modification of the original job config will appear as modifications by "system" in the changelog.

Alex O
  • 7,746
  • 2
  • 25
  • 38
0

I recently had the same issue. It is described here: https://issues.jenkins-ci.org/browse/JENKINS-43693

The solution is to make sure all your branch sources have an id specified that does not change. When JobDSL runs your definitions, if an ID is not specified it will generate a new one. Multibranch pipelines then lose track of which branches have been built, thus the re-building. This ID must be unique across all jobs, so I usually use a variation of the job name itself.

For bitbucket branch, sources, it's specified like so:

multibranchPipelineJob(jobName) {
    branchSources {
        branchSource {
            source {
                bitbucket {
                    id 'some-unique-constant-id'
                    //etc
                }
            }
        }
    }
}

For git, it is similar:

multibranchPipelineJob(jobName) {
  branchSources {
    branchSource {
      source {
        git {
          id 'must-be-unique'
        }
      }
    }
  }
}
GJP
  • 415
  • 4
  • 13