0

I'm running version 2.249.3 of jenkins and try to create a pipeline that remove all old instances.

for (String Name : ClustersToRemove) {

    buildRemoveJob (Name, removeClusterBuilds, removeClusterBuildsResults)              
    parallel removeClusterBuilds

}

and what the method does is :

def buildRemoveJob (Name, removeClusterBuilds, removeClusterBuildsResults) {
    
removeClusterBuilds[clusterName] =   {
    //Random rnd = new Random()
    //sleep (Math.abs(rnd.nextInt(Integer.valueOf(rangeToRandom)) + Integer.valueOf(minimumRunInterval)))
    removeClusterBuildsResults[clusterName] = build job: 'Delete_Instance', wait: true,  propagate: false, parameters: [
            [$class: 'StringParameterValue', name: 'Cluster_Name', value: clusterName],
            
    ]
}

But... I get only one downstream job that is being launched. I found this bug https://issues.jenkins.io/browse/JENKINS-55748 but it looks that someone must have solved this issue since it's a very common scenario.

Also here - How to run the same job multiple times in parallel with Jenkins? - I found a documentaion but looks that it does not apply from same jobs

The version of build pipeline plugin is 1.5.8

NZL
  • 71
  • 1
  • 7

2 Answers2

0

From the parallel command documentation:

Takes a map from branch names to closures and an optional argument failFast which will terminate all branches upon a failure in any other branch:

    parallel firstBranch: {
        // do something
    }, secondBranch: {
        // do something else
    },
    failFast: true|false

So you should first create a map of all executions and then run them all in parallel.

In your example, you should first iterate over the strings and create the executions map, then pass it to the parallel command. Something like this:

def executions =  ClustersToRemove.collectEntries {
    ["building ${it}": {
        stage("Build") {
            removeClusterBuildsResults[it] = build job: 'Delete_Instance', wait: true,  propagate: false,
                    parameters: [[$class: 'StringParameterValue', name: it, value: clusterName]]
        }
    }]
}

parallel executions

or without the variable:

parallel ClustersToRemove.collectEntries {
...
Noam Helmer
  • 5,310
  • 1
  • 9
  • 29
0

Yes to be straight..

Depends on number of agents you have.

if you have single agent then other triggers go to queue state.

Hope that answers your question.