【问题标题】:How to make jenkins move to the next stage if its "terminal" has been blocked?如果jenkins的“终端”被阻塞,如何让jenkins进入下一阶段?
【发布时间】:2016-11-17 20:56:43
【问题描述】:

我正在尝试运行 http 调用以测试将在 jenkins 机器中运行的实时 Web 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 步骤。 Web 应用程序完全启动后如何运行npm test

【问题讨论】:

    标签: node.js jenkins jenkins-pipeline


    【解决方案1】:

    一种方法是在 Web 应用程序的末尾加上 & 来启动它,这样它就会在后台运行。即

    npm start &

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

    npm start > output.txt &

    然后在下一步中,循环直到“开始”消息可用,例如:

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

    代码未测试:)

    【讨论】:

    • 如果我这样做了,我如何确定只有在应用程序完成启动程序后才能开始测试?
    • Julio Rodrigues 你是如何解决这个问题的?我也有类似的问题
    猜你喜欢
    • 1970-01-01
    • 2020-07-19
    • 2016-07-06
    • 2015-12-30
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多