在我的
Jenkins
管道:
saltnodes.each {
node('slave1') {
stage('Salt call') {
saltresult = salt authtype: 'pam', clientInterface: runner(
function: 'state.orch', mods: 'test.deploy', pillarvalue: "$someParams"),
credentialsId: 'mycreds', servername: "http://$it"
println JsonOutput.prettyPrint(saltresult)
}
}
在这部分代码中,我试图实现
"try"
和
"catch"
异常处理程序:
import groovy.transform.Field
saltnodes.each {
node('slave1') {
stage('Salt call') {
try{
@Field result = salt authtype: 'pam', clientInterface: runner(
function: 'state.orch', mods: 'test.deploy', pillarvalue: "$someParams"),
credentialsId: 'mycreds', servername: "http://$it"
}
catch (e){
def jsonSlurper = new JsonSlurper()
println jsonSlurper.parseText(result)
}
}
但当我使用
@Filed
在这里转换,我得到
"Null pointer exception"
我还能怎么通过
"result"
变量至
“捕获”
块以便在那里打印结果变量的内容?