How to use Build User Vars Plugin with Pipeline?

Issue

How do I access variables provided by Build User Vars Plugin in Pipeline jobs.

Environment

Resolution

Example:

wrap([$class: 'BuildUser']) {
 // https://wiki.jenkins-ci.org/display/JENKINS/Build+User+Vars+Plugin variables available inside this block

  sh 'echo ${BUILD_USER}'
}

NOTE: Requires version 1.5 of Build User Vars Plugin

Have more questions? Submit a request

3 Comments

  • 1
    Avatar
    Nachoyo89 Nachoyo89

    I tried this on multibranch pipeline and it doesn't work.

    stage('stage1') {
      steps {
        wrap([$class: 'BuildUser']) {
          sh 'echo "${BUILD_USER}"'
          sh 'echo "${BUILD_USER_ID}"'
          sh 'echo "${BUILD_USER_EMAIL}"'
        }
    }


    I am using version 1.5 of Build User Vars Plugin

    Edited by Nachoyo89 Nachoyo89
  • -2
    Avatar
    Joe Tavin

    Try without invoking sh, just echo direct like so:

    stage('stage1') {
      steps {
        wrap([$class: 'BuildUser']) {
          echo "${BUILD_USER}"
          echo "${BUILD_USER_ID}"
          echo "${BUILD_USER_EMAIL}"
        }
    }
  • 0
    Avatar
    Denis Chekhlov

    https://stackoverflow.com/questions/35902664/get-user-name-from-jenkins-workflow-pipeline-plugin/48649228#48649228

    ```

    pipeline {
      agent any
    
      stages {
        stage('build user') {
          steps {
            wrap([$class: 'BuildUser']) {
              sh 'echo "${BUILD_USER}"'
            }
          }
        }
      }
    }
    ```

    WORKS!

Please sign in to leave a comment.