I want to run a variable set of Jenkins jobs in parallel upon a run of one job. The master job takes a parameter I want to pass down on each job.
I have the following code for the pipeline, where TARGET_BRANCH is the param the parent takes and passes down to the children:
@NonCPS
def makeList(TARGET_BRANCH) {
def targets = [:]
hudson.model.Hudson.instance.getView('WSS').items.each {
if (it.fullName.startsWith('wss-run')) {
def fullName = it.fullName;
targets['Switching '.concat(fullName)] = {
build job: fullName, parameters: [string(name: 'TARGET_BRANCH', value: TARGET_BRANCH)]
}
}
}
return targets
}
pipeline {
agent any
stages {
stage('Switch') {
steps {
script {
parallel makeList("${TARGET_BRANCH}")
}
}
}
}
}
And this sort of works, in that the child jobs do build... But the master job itself appears to hang, and shows its status as still running the first child job, even after all child jobs are done.
Also worth pointing out, the parameter in both the parent and child are defined as a persistent string and the console output shows
The parameter 'TARGET_BRANCH' did not have the type expected by {job_name}. Converting to Persistent String Parameter.
I'm not sure how to properly cast it in advance and if maybe this cast is the reason the main job fails to end. I don't really care about the cast warning though. I only care that the main job finishes when all child jobs finish (be they successful or failed).
I am using the latest Jenkins LTS version at this time (2.346.2) with all plugins up to date.
What am I doing wrong?