我正在尝试获取在 Jenkinsfile 中运行构建的用户的名称:
...
user = User.current().getFullName()
...
但得到“系统”。如何获得正确的用户名?
詹金斯 1.651.3
我正在尝试获取在 Jenkinsfile 中运行构建的用户的名称:
...
user = User.current().getFullName()
...
但得到“系统”。如何获得正确的用户名?
詹金斯 1.651.3
找到解决方案:
def build = currentBuild.rawBuild
def cause = build.getCause(hudson.model.Cause.UserIdCause.class)
def name = cause.getUserName()
echo "User: " + name
打印运行构建的用户名。
如果您遇到“不允许使用脚本”,这也可以;
...然后包装您的步骤,如下所示:
steps {
script {
wrap([$class: 'BuildUser']) {
var name = "${BUILD_USER}"
}
}
}