Jenkins Pipeline waitUntil bash 命令返回特定字符串

Mos*_*she 4 jenkins jenkins-groovy jenkins-pipeline

我有一个管道阶段,我等待从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!!!"
    }
}
Run Code Online (Sandbox Code Playgroud)

执行是这样的:

+ 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)
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

Tra*_*nin 5

来自waitUntil的帮助:

重复运行它的主体,直到它返回 true。如果它返回 false,则等待一段时间并再次尝试。——

您的执行输出看起来与它正在等待output == "hello"匹配的完全一样。也许文件的内容/tmp/test.txt不完全是hello. 您可能在其中包含一些空格,例如新行作为最后一个字符。