how to run a jenkins job parralley with different parameter value?

MelvinaN

Junior Member
I have a job named READ_LOGS, which takes a serverName as parameter and ssh into the server and cat the log file.

parameter: serverName

Build step: execute shell script, the script contents below command

ssh -f user@serverName 'cat /tmp/test.log'
I have another job named START_POC, which does provide list of 6 servers as choice parameter. While running the job, user selects any number of servers to get logs from. I want to run the START_POC for x many time the servers selected by user and it should run x many time parallel.

Approach 1: I tried below approach but did not work for me.

def runparallellogs = []

for (server in servers){
runparallellogs["run-${server }"] = {
buildJob = build job: 'READ_LOGS', parameters: [string(name: 'serverName', value: "${server")]
}
}
parallel runparallellogs
This approach gives me java.lang.IllegalArgumentException: argument type mismatch error

Approach 2: (ref)

parallel (
{ build("READ_LOGS", serverName: server1) },
{ build("READ_LOGS", serverName: server2) },
{ build("READ_LOGS", serverName: server3) },
{ build("READ_LOGS", serverName: server4) }
)
Approach 3:

def testJobs = []
for (server in servers) {
def jobParams = [serverName: server]
def testJob = {
// call build
build(jobParams, "READ_LOGS")
}
println jobParams
testJobs.add(testJob)
}

parallel(testJobs)
I am getting the same error for both the approach.

java.lang.IllegalArgumentException: Expected named arguments but got [org.jenkinsci.plugins.workflow.cps.CpsClosure2@598ac18e, org.jenkinsci.plugins.workflow.cps.CpsClosure2@238eaf6c, org.jenkinsci.plugins.workflow.cps.CpsClosure2@200d849d, org.jenkinsci.plugins.workflow.cps.CpsClosure2@6ddfc97b]
I just want to run the READ_LOGS logs job from START_POC job for the x number of params selected by user. Any help would be appreciated in this scenario.
 
Back
Top