我有一个管道阶段,我等待从 sh
脚本中获取某个字符串,并且只有当字符串匹配时,才继续到下一阶段,但是,它没有按预期工作:
node('master') {
stage("wait for bash completion") {
waitUntil {
def output = sh returnStdout: true, script: 'cat /tmp/test.txt'
output == "hello"
}
}
stage("execute after bash completed") {
echo "the file says hello!!!"
}
}
执行是这样的:
+ cat /tmp/test.txt
[Pipeline] }
Will try again after 0.25 sec
[Pipeline] {
[Pipeline] sh
[workspace] Running shell script
+ cat /tmp/test.txt
[Pipeline] }
Will try again after 0.3 sec
[Pipeline] {
[Pipeline] sh
[workspace] Running shell script
+ cat /tmp/test.txt
[Pipeline] }
Will try again after 0.36 sec
...
(so on and so forth)
我错过了什么?
最佳答案
来自 waitUntil
的帮助:
您的执行输出看起来就像它正在等待 output == "hello"
匹配。也许文件 /tmp/test.txt
的内容不完全是 hello
。你可能有一些空格,例如新行作为最后一个字符。
关于Jenkins Pipeline waitUntil bash 命令返回特定字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53987649/