获取触发用户:
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")
}
}
}
}
标签:pipeline,notes,currentBuild,echo,USER,upstreamBuilds,jenkins,null,BUILDER From: https://www.cnblogs.com/dylanchu/p/16722755.htmlhttps://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