Under http://[JENKINS_NAME]/job/[JOB_NAME]/[BUILD_NUMBER]/
I can see Started by user [USER_NAME].
I want to get that username f
You could get the build user from Jenkins environment (i.e as an env var). If you use Jenkins 2 pipeline, For example: pipeline {
//rest of the pipeline
stages {
stage('Build Info') {
steps {
wrap([$class: 'BuildUser']) {
sh 'java -jar .jar'
}
}
}
}
In your java app you should be able to get the environment variable using System.getenv("BUILD_USER")
or else you could pass it as a JVM arg. Ex: sh 'java -jar -DbuildUser=$BUILD_USER
and get the buildUser system property in the application.
On older version of Jenkins, you may use Build User Vars Plugin or Env Inject plugin. As in the answers on this question. how to get the BUILD_USER in Jenkins when job triggered by timer