如果使用 jenkinsfile (jenkins 管道) 在控制台日志中找到文本,则使构建不稳定



我正在尝试登录到一个实例并检查文件test.txt是否为空,然后echo ..使用 jenkins 管道 (jenkinsfile) 使构建不稳定但这是行不通的。 我有这个:

post {
always {
sh "ssh ubuntu@$Ip 'if [ -s test.txt ] ; then echo some text && cat test.txt'"
currentBuild.result = 'UNSTABLE'
}
}

与其执行上述操作,我是否可以解析最新版本的控制台日志以查找某些内容,例如:some text如果发现,我想使构建不稳定

您需要从脚本中返回标准:

String stdOut = sh returnStdout: true, script: "ssh ubuntu@$Ip 'if [ -s test.txt ] ; then echo some text && cat test.txt'"
if (stdOut == "") {
currentBuild.status = 'UNSTABLE'
}

或者,可以使用returnStatus返回脚本的退出代码。可在此处找到sh步骤的文档

最新更新