I want to have a job to set the environment variable and use these environment variables in all the next jobs. How can I set environment variable through Jenkins ?
Technically, you can't pass env variables from one job to the next, and I'm not aware of a plugin to do that out of the box.
There is a technique however. The idea is to create a properties file in the first job (e.g. exported.properties), add that file to the job artifacts, and then import this file via the EnvInject plugin in the second job.
This pre-supposes that you have some link between the first and second job, which is typically achieved with the Copy Artifact plugin, but a number of workflow-like plugins can help you as well.
For example, for creating the properties file, add a step "Execute shell", with e.g.
echo "# Saving some version properties
BUILD_VERSION=${BuildVersion}
BUILD_NODE_NAME=${NODE_NAME}
SOURCE_JOB=${JOB_NAME}
" > ${WORKSPACE}/BuildVersion.properties
Of course, you can use other build steps, e.g. Windows shell, groovy script, etc... each with their specific syntax of course.
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