我正在尝试登录到一个实例并检查文件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
步骤的文档