Blog

How to get username logged in Jenkins from Jenkins Pipeline Plugin?

get-username-logged-in-Jenkins-Pipeline
Jenkins

How to get username logged in Jenkins from Jenkins Pipeline Plugin?

You can access the current user’s username who triggered in the pipeline build using “BuildUser” wrapper in Jenkins.

Lets see how to retrieve the username of the user who triggered the build:

node {
    wrap([$class: 'BuildUser']) {
        def user = env.BUILD_USER_ID
        echo "Username who triggered the build: ${user}"
    }
}

In this script, the wrap([$class: ‘BuildUser’]) block ensures that the user information is available within the enclosed block. The env.BUILD_USER_ID variable holds the username of the user who triggered the build. Finally, the echo step is used to print out the retrieved username.

Make sure that the Build User Vars Plugin is installed and properly configured in your Jenkins instance for this approach to work correctly.

View Post

Spread the love

Leave your thought here

Your email address will not be published. Required fields are marked *