Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 587
idok Avatar asked Dec 02 '25 18:12

idok


1 Answers

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.

like image 161
Zloj Avatar answered Dec 05 '25 03:12

Zloj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!