Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39682

Generated Multibranch Pipeline Job does not index branches

      Using a JobDSL script to generate a multibranch Pipeline job does not trigger a branch index to find Jenkinsfile

      Here is a simple dsl job

      multibranchPipelineJob(repo) {
        branchSources {
          github {
            scanCredentialsId(credentials)
            repoOwner(credentials)
            repository(repo)
          }
        }
      }
      

      Using this created the job fine but did not trigger a branch scan until I manually triggered a branch index. It also works if you open the multibranch job configuration and save it with no changes.

      Creating a multibranch job directly from the UI works fine.

      The only way I can trigger a branch index is to add a triggers section to the command to periodically scan every minute. I then had to create 3 build steps:

      1. JobDSL to create mutlibranch Pipeline job with a trigger set to 1 minute
      2. Shell step to Sleep for 60 seconds
      3. JobDSL to modify the multibranch Pipeline job and turn off the trigger.

          [JENKINS-39682] Generated Multibranch Pipeline Job does not index branches

          Patrick Wolf created issue -

          Patrick Wolf added a comment -

          per jglick: probably `job-dsl` should be enhanced to ensure that for a `ComputedFolder` it automatically calls `scheduleBuild` after creation

          Patrick Wolf added a comment - per jglick : probably `job-dsl` should be enhanced to ensure that for a `ComputedFolder` it automatically calls `scheduleBuild` after creation
          Jesse Glick made changes -
          Labels New: multibranch

          Job DSL uses standard Jenkins API to create jobs, specifically Jenkins#createProjectFromXML(String name, InputStream xml). If the job does not trigger after creating from Job DSL, it will probably also not trigger after creating through CLI or REST API which use the same API internally. This should not be fixed at the consumer side of the API. It needs either to be fixed in core or in Multibranch Pipeline plugin.

          Daniel Spilker added a comment - Job DSL uses standard Jenkins API to create jobs, specifically Jenkins#createProjectFromXML(String name, InputStream xml) . If the job does not trigger after creating from Job DSL, it will probably also not trigger after creating through CLI or REST API which use the same API internally. This should not be fixed at the consumer side of the API. It needs either to be fixed in core or in Multibranch Pipeline plugin.
          Daniel Spilker made changes -
          Component/s New: core [ 15593 ]
          Component/s New: workflow-multibranch-plugin [ 21465 ]
          Daniel Spilker made changes -
          Assignee Original: Daniel Spilker [ daspilker ]
          Patrick Wolf made changes -
          Link New: This issue is related to JENKINS-38887 [ JENKINS-38887 ]
          Stephen Connolly made changes -
          Labels Original: multibranch New: multibranch scm-api-tidy-scrub
          Jesse Glick made changes -
          Component/s New: cloudbees-folder-plugin [ 18137 ]
          Component/s Original: core [ 15593 ]
          Component/s Original: workflow-multibranch-plugin [ 21465 ]

          Brian Saville added a comment -

          We worked around this by immediately queuing the job initially - something like this:

          def exists = jenkins.model.Jenkins.getInstance().getItemByFullName(jobPath)
          if (!exists) {
            queue(jobPath)
          }
          

          Brian Saville added a comment - We worked around this by immediately queuing the job initially - something like this: def exists = jenkins.model.Jenkins.getInstance().getItemByFullName(jobPath) if (!exists) { queue(jobPath) }

            daspilker Daniel Spilker
            hrmpw Patrick Wolf
            Votes:
            7 Vote for this issue
            Watchers:
            22 Start watching this issue

              Created:
              Updated:
              Resolved: