pipline获取触发任务的用户名

stage('获取触发任务用户') {
steps {
script {
def BUILD_TRIGGER_BY = "${currentBuild.getBuildCauses()[0].shortDescription}"
BUILD_TRIGGER_BY = sh (script: "echo ${BUILD_TRIGGER_BY}|awk -F ' ' '{print $NF}'", returnStdout: true).trim()
echo "BUILD_TRIGGER_BY: ${BUILD_TRIGGER_BY}"
}
}
}

参考至:https://stackoverflow.com/questions/36194316/how-to-get-the-build-user-in-jenkins-when-job-triggered-by-timer

posted @ 2021-08-11 14:26  没有猫的猫奴  阅读(171)  评论(0)    收藏  举报