I would like to be able to do something like:
AOEU=$(echo aoeu)
and have Jenkins set AOEU=aoeu
.
The Environment Variables section in Jenkins doesn't do that. Instead, it sets AOEU='$(echo aoeu)'
.
How can I get Jenkins to evaluate a shell command and assign the output to an environment variable?
Eventually, I want to be able to assign the executor of a job to an environment variable that can be passed into or used by other scripts.
The simplest way
You can use EnvInject plugin to injects environment variables at build startup. For example:
How you know it's working
We use groovy job file:
Jenkin is having inbuilt support for this, using which your can access value of local variables as global environment variables. You can achieve this in following 4 simple steps.
Step-1
Step-2
Under "Add Build Step" drop-down, select "Inject environment variable"
Step:3
Enter the fully qualified file name that you created previously(
<some_name>.properties
) in Properties File Path field.Step-4
Now it's available as a Jenkins environment variable and you can use as needed in Post-build-Action . $variable_name1 like any other environment variable.
Here is a nice post regarding this
EnvInject Plugin aka (Environment Injector Plugin) gives you several options to set environment variables from Jenkins configuration.
By selecting
Inject environment variables to the build process
you will get:Properties File Path
Properties Content
Script File Path
Script Content
and finally
Evaluated Groovy script
.Evaluated Groovy script
gives you possibility to set environment variable based on result of executed command:execute
method:Groovy
code:(More details about each method could be found in build-in help (?))
Unfortunately you can't do the same from
Script Content
as it states:You can try something like this
This can be done via EnvInject plugin in the following way:
Create an "Execute shell" build step that runs:
Create an Inject environment variables build step and set "Properties File Path" to
propsfile
.Note: This plugin is (mostly) not compatible with the Pipeline plugin.