在我的jenkins脚本化管道中,我正在远程计算机上运行bash脚本。我尝试了以下几种方法,但未满足要求:
-由于我有传递给远程服务器命令以运行sshScript
不支持的参数
-publish over ssh plugin
在我也不想要的詹金斯日志中显示我的execCommand。
因此,我使用sshPut将我的bash脚本放置在远程服务器上,并使用sshCommand以及带有参数的远程脚本在该服务器上运行它。一切都很好,除非遇到错误,我需要退出并做其他事情。发生的情况是如果发生错误,jenkins作业出口将异常执行。可以通过为sshCommand设置failOnError: false
来覆盖它;但是那样的话,乔布就永远不会失败。
我需要,如果sshCommand:退出并出现错误,那么我需要执行诸如send slackNotify之类的操作。那么,有没有像statusCode
或exit-bhalah
这样的东西可以像!= 0
那样比较并执行某些功能呢?
我在想类似
stage('Deploy'){
// some blocks here
sshCommand remote: remote, failOnError: false, command: "bash Filescript.sh $ARGS1"
if (statusCode != 0){
//do my thing here
}
}
答案 0 :(得分:0)
您可以使用try-catch:
stage('Deploy'){
// some blocks here
try {
sshCommand remote: remote, command: "bash Filescript.sh $ARGS1"
}
catch {
//do my thing here
}
}