I don't understand why an error occurs:
stage('name') {
steps {
script {
def jsonObj = new JsonSlurper().parseText( env.work_servers )
for(item in jsonObj){
cmd("my command --param1=${item.srv} --param2=${item.port}")
}
}
}
}
getting an error, error stack https://pastebin.com/V09ZXrif
even if you replace the cmd method call with sh, nothing changes
If you invoke commands without a loop, everything works
stage('name') {
steps {
script {
def srv = "..."
def port = "..."
cmd("my command --param1=${srv} --param2=${port}")
srv = "..."
port = "..."
cmd("my command --param1=${srv} --param2=${port}")
}
}
}
this also works
stage('name') {
steps {
script {
def jsonObj = new JsonSlurper().parseText( env.work_servers )
for(item in jsonObj){
echo item
}
}
}
}
def cmd(command) {
result = ""
if (isUnix()) {
result = sh(
script: command,
returnStdout: true
).trim()
} else {
bat "chcp 65001\n${command}"
}
return result
}