我在我的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"
变量传递给"catch"
块,以便在那里打印结果变量的内容?
最后,我能够弄清楚。问题是我错误地理解了错误输出。错误期间的输出是提高excepetion但不是可变内容。
结果我做了下一个:
saltnodes.each {
node('slave1') {
stage('Salt call') {
try{
result = salt authtype: 'pam', clientInterface: runner(
function: 'state.orch', mods: 'test.deploy', pillarvalue: "$someParams"),
credentialsId: 'mycreds', servername: "http://$it"
println result
}
catch (com.waytta.SaltException e){
def jsonSlurper = new JsonSlurper()
println jsonSlurper.parseText(e.getMessage())
}
}