I am working on a Django project, I have integrated it withJenkins Multibranch Pipeline. I cannot inject environment variables by the Multibrach Pipeline option even after installing the Environment Injector plugin.
I have evironment variables like DB_PASSWORD that must be included in the envvars.
Any insight will be highly appreciated.
Since you require secrets, the best practice way is to use the withCredentials plugin which can load credentials stored in Jenkins credential store and expose them as ENV variables to code executed within its block/closure. Using withCredentials does not expose them in Jenkins logs
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: 'DB_Creds',
usernameVariable: 'DB_USERNAME',
passwordVariable: 'DB_PASSWORD']]) {// do stuff }
For non sensitive Env vars use withEnv
withEnv(["AWS_REGION=${params.AWS_REGION}"]) {// do stuff }
If for whatever reason you want Env vars set across your entire pipeline (not entirely recommended but sometimes necessary):
env.MY_VAR='var'
echo("My Env var = ${env.MY_VAR}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With