Srinithin
Srinithin

Reputation: 53

How to parelelly execute a list imported from another Groovy file?

I am importing a list from another groovy file and Utilizing it to iterate through the content:

First.groovy

def getContent() {
    def content = ["one", "two"]
    return content
}

return this;

And calling it like:

def first = load 'First.groovy'
def content = first.getContent()

stage("Build services") {
              parallel content { CONTENT_NAME ->
                 [CONTENT_NAME, {
                     //iterate through each job
                     try { 
                        some code;  
                       } 
                    catch (err) {
                         echo err.toString()
                         currentBuild.result = 'FAILURE'
                         throw err
                     }
                 }]
             }

But I am getting error -

hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.call() is applicable for argument types: (org.jenkinsci.plugins.workflow.cps.CpsClosure2) values: 
[org.jenkinsci.plugins.workflow.cps.CpsClosure2@23856748]
Possible solutions: tail(), tail(), wait(), last(), last(), any()

Any clue on resolving this?

Upvotes: 0

Views: 438

Answers (1)

Michael Kemmerzell
Michael Kemmerzell

Reputation: 5256

parallel: Execute in parallel Takes a map from branch names to closures

You need to create a map first and then execute it per parallel. Your content is only a List.

I would suggest a different approach on how to build the tasks:

def parallelTasks = [:]
for (element in content) {
    parallelTasks["${element}"] = {
      echo "${element}"
  }
}
parallel parallelTasks

Upvotes: 1

Related Questions