Reputation: 4076
I am trying to get the name of the user that's running a build in Jenkinsfile:
...
user = User.current().getFullName()
...
but get "SYSTEM". How get correct username?
Jenkins 1.651.3
Upvotes: 4
Views: 10220
Reputation: 51
If you encounter "Scripts not allowed" this also works;
Install the Build User Vars plugin found here
... then wrap your step, something like this:
steps {
script {
wrap([$class: 'BuildUser']) {
var name = "${BUILD_USER}"
}
}
}
Upvotes: 5
Reputation: 4076
Found solution:
def build = currentBuild.rawBuild
def cause = build.getCause(hudson.model.Cause.UserIdCause.class)
def name = cause.getUserName()
echo "User: " + name
print name of user which run build.
Upvotes: 10