Reputation: 30723
I have installed the EnvInject plugin of Jenkins. I add it in the properties content (In script content also doesn't work: echo's nothing) I able to set environment variable e.g.:
TEST="hello world"
In shell:
echo ${TEST}
Output: Hello World
But when I try to put the output of a command in my variable it doesn't work:
HOSTNAME=`hostname`
In Shell
echo ${HOSTNAME}
Output: `hostname`
While when I set the environment variable in my shell (without the plugin it works): In Shell
HOSTNAME=`hostname`
echo ${HOSTNAME}
Output: localhost
Upvotes: 1
Views: 1015
Reputation: 7805
From job configuration you should use Inject environment variables to the build process / Evaluated Groovy script
.
Depending on the configuration you could execute command and save it in map containing environment variables:
return [HOSTNAME: 'hostname'.execute().text]
or run Groovy
equivalent:
return [HOSTNAME: java.net.InetAddress.getLocalHost().getHostName()]
Upvotes: 1