node { withEnv(['MYTOOL_HOME=/usr/local/mytool']) { sh '$MYTOOL_HOME/bin/start' } }
(Note that here we are using single quotes in Groovy, so the variable expansion is being done by the Bourne shell, not Jenkins.)
From Groovy code inside the block, the value is also accessible as env.VARNAME
.
You can write to this property rather than using the withEnv
step,
though any changes are global to the workflow build so should not include node-specific content such as file paths:
env.MYTOOL_VERSION = '1.33' node { sh '/usr/local/mytool-$MYTOOL_VERSION/bin/start' }
A set of environment variables are made available to all Jenkins projects, including workflows. The following is a general list of variables (by name) that are available; see the notes below the list for Workflow-specific details.
The following variables are currently unavailable inside a workflow script:
EXECUTOR_NUMBER
NODE_NAME
NODE_LABELS
WORKSPACE
SVN_REVISION
mail to: 'devops@acme.com', subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) is waiting for input", body: "Please go to ${env.BUILD_URL} and verify the build"