gpt4 book ai didi

Jenkins 声明式管道 : find out triggering job

转载 作者:行者123 更新时间:2023-12-02 12:09:45 25 4
gpt4 key购买 nike

我们有一个 Jenkins 作业,它使用 declarative pipeline .

此作业可以由不同的其他构建触发。

在声明性管道中,如何找出哪个构建触发了管道?

最佳答案

下面的代码示例

pipeline {    agent any    stages {        stage('find upstream job') {            steps {                script {                    def causes = currentBuild.rawBuild.getCauses()                    for(cause in causes) {                        if (cause.class.toString().contains("UpstreamCause")) {                            println "This job was caused by job " + cause.upstreamProject                        } else {                            println "Root cause : " + cause.toString()                        }                    }                }                  }        }    }}

您可以检查作业的 REST API 以获取如下所示的额外信息

{  "_class" : "org.jenkinsci.plugins.workflow.job.WorkflowRun",  "actions" : [    {      "_class" : "hudson.model.ParametersAction",      "parameters" : [      ]    },    {      "_class" : "hudson.model.CauseAction",      "causes" : [        {          "_class" : "hudson.model.Cause$UpstreamCause",          "shortDescription" : "Started by upstream project \"larrycai-sto-46908390\" build number 7",          "upstreamBuild" : 7,          "upstreamProject" : "larrycai-sto-46908390",          "upstreamUrl" : "job/larrycai-sto-46908390/"        }      ]    },

引用:

关于Jenkins 声明式管道 : find out triggering job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46908390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com