有时候在pipeline中需要获取执行build 的用户信息,如用户名(用于自动给用户授权另外一个工具)用户邮箱(用于自动给用户发邮件)。这时可以使用插件: Buid User Var
具体pipeline 写法如下:
pipeline {
agent any
stages {
stage('Build_user_info') {
steps {
script{
wrap([$class: 'BuildUser']) { //plugin:Buid User Var
sh'''
echo $BUILD_USER_ID
echo $BUILD_USER_EMAIL
env
'''
}
}
}
}
}
}