Jenkins Pipeline - wait for non-job items (ComputedFolder, Multibranch Pipeline Project)
Asked Answered
S

0

6

I'm using multibranch pipeline projects in Jenkins. I let Jenkins index new branches. I need Jenkins to wait until the indexing of a multibranch pipeline project is complete.

This is my current code:

def triggerScanMultibranchPipeline(projectDir, repo) {
    def multibranchProject = Jenkins.instance.getItemByFullName "$projectDir/$repo"
    multibranchProject.scheduleBuild()
    while (multibranchProject == null || multibranchProject.isDisabled()) {
        sleep 1000 //1000 milliseconds = 1 second
    }
    sleep time: 1, unit: 'SECONDS'
}

Already tried:

  • change (second) sleep to 30 seconds

This increases the duration of the build each time triggerScanMultibranchPipeline is called.

I cannot use "wait: true" for the indexing to complete, because waiting for non-job items is not supported. See https://github.com/jenkinsci/pipeline-build-step-plugin/blob/pipeline-build-step-2.13/src/main/java/org/jenkinsci/plugins/workflow/support/steps/build/BuildTriggerStepExecution.java#L80

How can I let Jenkins wait until the branch indexing of the Multibranch Pipeline Project is complete?

Spann answered 8/12, 2020 at 15:9 Comment(1)
Why do you need to trigger the scanning manually? is it to find new branches? if so, with the correct configuration they are added automatically upon creation using the web hooks.Christly

© 2022 - 2024 — McMap. All rights reserved.