I\'m trying to automatically trigger \'Branch Indexing\' on a Multibranch Pipelines job in Jenkins.
At the moment, only one method seems to actually work, which is p
The method ComputedFolder.scheduleBuild() can be invoked from a groovy script.
I have just triggered branch indexing in one multibranch pipeline project from the groovy code in a different multibranch pipeline project, which is then triggering a downstream build in that project.
The code is something like:
@NonCPS
void scanRepo(String downStreamProjectName) {
Jenkins.instance.getItemByFullName(downStreamProjectName).scheduleBuild()
}
...
String downStreamProject = 'my-folder/my-multibranch-project'
String downStreamJob = "${downStreamProject}/${env.BRANCH_NAME}"
if (Jenkins.instance.getItemByFullName(downStreamJob) == null) {
scanRepo(downStreamProject)
while (Jenkins.instance.getItemByFullName(downStreamJob) == null) {
sleep(1)
}
}
build([job: downStreamJob, wait: false, quietPeriod: 0])
Notice that Jenkins.instance.getItemByFullName(downStreamProjectName) is the WorkflowMultiBranchProject which is not Serializable, so some care needs to be taken.