Question

I am trying to set job environment variables. Some variables are set from other environment variables. For instance on Windows:

var1=this
var2=that
var3=other
var4=%var1%_%var2%_%var3%

And I'd like to see var4 set as 'this_that_other'. I tried setting the first three as job variables and the fourth as a build variable. No joy.

Was it helpful?

Solution

You can do this using the EnvInject Plugin for Jenkins. Here var1, var2 and var3 are build parameters, or predefined environment variables. The same thing can also be done using Groovy.

enter image description here

OTHER TIPS

Because you set the variable only in the current process scope. As you said if you don't want to use file to store and retrieve, another option is making the environment variable setting machine wise, if that serve your need and won't have any side effects.

If you could install PowerShell plugin, use PowerShell script is very easy to do this:

[Environment]::SetEnvironmentVariable("VAR4", $WhatEverYouWant, "Machine")

This makes the VAR4 variable available immediately on machine level, meaning in all the other processes.

It does work to set var4 in a batch command if that is where var4 is needed:

set var4=%var1%_%var2%_%var3%

var4 now has the desired value for the duration of the batch command, but not for any subsequent build steps. This doesn't help me because I need to use var4 in an ant command.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top