如果 "terminal" 已经被阻塞,如何让 jenkins 进入下一阶段?

How to make jenkins move to the next stage if its "terminal" has been blocked?

我正在尝试 运行 http 调用以测试将在 jenkins 机器中 运行 的实时网络 api。

这是已使用的管道脚本。

stage 'build'
    node {
        git url: 'https://github.com/juliomarcos/sample-http-test-ci/'
        sh "npm install"
        sh "npm start"
    }
stage 'test'
    node {
        sh "npm test"
    }

但是 jenkins 不会移动到 test 步骤。网络应用程序完全启动后,如何运行 npm test

一种方法是在结尾处使用 & 启动网络应用程序,这样它将 运行 在后台运行。即

npm start &

您可以尝试将 npm start 的输出重定向到这样的文本文件:

npm start > output.txt &

然后在下一步中,循环直到 "started" 消息可用,例如:

tail -f output.txt | while read LOGLINE
do
   [[ "${LOGLINE}" == *"listening on port"* ]] && pkill -P $$ tail
done

代码未测试:)