def call() {
node {
timestamps {
ansiColor('xterm') {
try {
powershell """
throw new Exception("ERROR: This is a test Exception.")
"""
} catch (error) {
println("Caught error: ${error.getMessage()}")
}
}
}
}
}
我尝试使用error.message,error.printStackTrace()和error.cause.getMessage(),但它们都没有打印错误消息。相反,我收到消息“脚本返回的退出代码1”。有人可以帮助我正确捕获错误消息吗?
我的理解是,您不能以相同的方式将异常从Powershell转到Groovy。
最终的行动课程将在您的PowerShell脚本中捕获异常,写入输出,没有错误,然后解析输出以解决此错误。 像这样的东西:
我没有解释,为什么詹金斯·乔布斯(Jenkins Jobs)对文档中所述的powershell错误没有反应:
https://www.jenkins.io/blog/2017/07/07/26/powershell-pipeline/powershell-pipeline/the wher the try
-ErrorAction Stop