Jenkins environment variable setup

Manual Feed

# set custom job name
jobName="your_job_name"
(note: by default, you can use $JOB_NAME which doesn't require any env setup)

# create a shell file and add the below statement
echo 'export VN_NAME="$jobName"' > ~/load_env.sh

# set user privilege
chmod 750 ~/load_env.sh

# temp env variable call
source ~/load_env.sh
echo $VN_NAME

Jenkins Plugin to inject ENV variable

  • By default you will have the Jenkins plugin EnvInject API Plugin
  • Go to Job > Build Environment  and select Inject environment variables to the build process
  • Set variable key and value as in below

Default Jenkins Configure

The environment variables can also be set through Global properties

  • Go to Manage Jenkins > Configure System > Global properties
  • Add the variable key and value

 

Leave a comment