idok
idok

Reputation: 652

Set BUILD_USER in Jenkins when the build process is time triggered

I am using 'Build User Vars Plugin' in Jenkins to get the user that caused the trigger. This works fine when it's triggered manually. BUILD_USER is set to SCMTrigger when the build process is triggered by Polling P4 as well. However, when the build is triggered periodically(time), BUILD_USER is blank. Is there a way to set the BUILD_USER env variable when triggered by time?

Upvotes: 3

Views: 2295

Answers (1)

Ivan
Ivan

Reputation: 2340

You can manually set that env variable.

if [ ${BUILD_CAUSE} == "TIMERTRIGGER" ]; then
  export BUILD_USER="Emmett Brown"
fi

${BUILD_CAUSE} is another Jenkins' environment variable. If you do not have that variable in a build - this maybe because it is set by EnvInject. The name is pretty much self-explaining.

Beware though, that setting BUILD_USER this way may or may not change the outcome environment variable accessible after the build in 'Environment variables' for the build. If you run into this issue - use EnvInject plugin. You can change any of Jenkins environment variables with this plugin, even BUILD_URL and such.

Upvotes: 2

Related Questions