首页 > 其他分享 >jenkins pipeline notes

jenkins pipeline notes

时间:2022-09-23 14:55:26浏览次数:80  
标签:pipeline notes currentBuild echo USER upstreamBuilds jenkins null BUILDER

获取触发用户:

def BUILDER_USER = "${currentBuild.getBuildCauses()[0].userId}"

由上游项目触发时获取上游项目构建信息和触发用户:

post {
    always {
        script {
            if ("${BUILDER_USER}" == "null") {
                echo "----------- BUILDER_USER is null (timer or upstream) -----------"
                echo "${currentBuild}"
                echo "${currentBuild.upstreamBuilds}"
                echo "${currentBuild.upstreamBuilds[0]}"  // timer触发时为"null",后续null.xxx将报错
                echo "${currentBuild.upstreamBuilds[0].projectName}"
                // echo "${currentBuild.upstreamBuilds[0].userId}" // error
                echo "${currentBuild.upstreamBuilds[0].buildCauses}"
                echo "${currentBuild.upstreamBuilds[0].buildCauses.userId}"
            } else {
                popo("${BUILDER_USER}", "BUILDER_USER is ${BUILDER_USER}, ${currentBuild.getAbsoluteUrl()}console")
            }
        }
    }
}

https://stackoverflow.com/questions/70291635/how-to-get-upstream-build-information-in-a-script-step-of-jenkins-classic-ui-pip
https://javadoc.jenkins.io/plugin/workflow-support/org/jenkinsci/plugins/workflow/support/steps/build/RunWrapper.html

标签:pipeline,notes,currentBuild,echo,USER,upstreamBuilds,jenkins,null,BUILDER
From: https://www.cnblogs.com/dylanchu/p/16722755.html

相关文章