【问题标题】:jenkins scripted Pipeline stage does not wait for its commands to finish executing詹金斯脚本化管道阶段不等待其命令完成执行
【发布时间】:2019-10-19 17:45:18
【问题描述】:

我编写了一个 jenkins 脚本管道,其中包含 3 个阶段。在每个阶段,我都调用 curl 命令来启动远程服务器上的 jenkins 作业。但是,问题是在第一阶段完成执行之前第二阶段正在执行。 请帮我解决这个问题?

node{
   properties([
        disableConcurrentBuilds()
    ])
    stage('stage1'){
       sh 'curl -X POST -H "Content-Type: application/json" -d "{         "tagname": "$tagname" }" -vs http://pkg.rtbrick.com:8080/generic-webhook-trigger/invoke?token=qwerty'
    }

    stage('stage2'){
        sh 'curl -X POST -H "Content-Type: application/json" -d "{ "tagname": "$tagname" }" -vs http://image.rtbrick.com:8080/generic-webhook-trigger/invoke?token=1234'
    }

     stage('stage3'){
       sh 'curl -X POST -H "Content-Type: application/json" -d "{ "tagname": "$tagname" }" -vs http://image.rtbrick.com:8080/generic-webhook-trigger/invoke?token=1804'}
    }
}

“Stage2”只有在“stage1”完成后才会开始。

【问题讨论】:

  • 嗨,Jay,你能分享一下你的工作执行的日志吗?
  • [Pipeline] { [Pipeline] properties [Pipeline] stage [Pipeline] { (build) [Pipeline] sh + curl -X POST -H Content-Type: application/json -d { tagname: ewetel-staging } -vs pkg.rtbrick.com:8080/generic-webhook-trigger/… * Trying 104.131.27.92... * 连接到 pkg.rtbrick.com 端口 8080 (#0) > POST /generic-webhook-trigger/invoke?token=qwerty HTTP/1.1 > Host : pkg.rtbrick.com:8080 > Content-Type: application/json > Content-Length: 27 } [27 bytes data] * 上传完全发送: 27 out of 27 bytes
  • 那是完整的日志?
  • 您真的可以使用管道中的完整日志更新您的问题吗?

标签: jenkins jenkins-pipeline


【解决方案1】:

将 Jenkins REST API 和 waitUntil 步骤与 timeout 结合使用是可行的(如果没有超时,它可能会永远挂起):

def response

timeout(30) {
    waitUntil {
        response = sh(
            script: 'curl http://pkg.rtbrick.com:8080/view/job/my-job/lastBuild/api/json | grep "\"result\":\"SUCCESS\""',
            returnStatus: true
        )

        return (response == 0)
    }
}

if (response != 0) {
    build.result = 'ERROR'
}

【讨论】:

  • 我需要在哪个阶段之后放置这个?
  • @JayashreeRanganath 在您需要等待工作完成的每个阶段之后。所以我说过,实际上在每个阶段。
  • 让我试着回复你
  • 我刚刚在我的管道中添加了以下行。触发的作业成功了,但它仍然在等待并且没有出来。
  • node{ stage('build'){ sh 'curl -X POST -H "Content-Type: application/json" -d "{ "tagname": "$tagname" }" -vs pkg.rtbrick.com:8080/generic-webhook-trigger/…'def response timeout(30) { waitUntil { response = sh( script: 'curl pkg.rtbrick.com:8080/job/Refresh-Custom-Apt-Repo/lastBuild/api/… | grep "\"result\":\"SUCCESS\""', returnStatus: true ) return (response == 0) } }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-18
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-13
  • 2016-10-08
相关资源
最近更新 更多