Home > other >  Jenkins does not recognize setting env variables using set -a
Jenkins does not recognize setting env variables using set -a

Time:05-25

I have a bash file that is used to set env variables. It is called setter.sh and contains something like this

set -x
var1="something"

in my jenkinsfile I do this

sh ". setter.sh"
sh "echo $var1"

However $var1 is not recognized. What could be the reasoning of this?

CodePudding user response:

Your issue is not the spaces, it's the step syntax. You have two separate steps (commands) in two separate shells. sh ". setter.sh" runs in one shell and quits. The second command, sh "echo $var1" runs in a separate shell that does not know about the first's environment.

Either use a multi-line shell command or Environment Injector plugin or some other means. (warning).

Also, set -x is not relevant to the question, but set option in subject is set -a (export), body is set -x (trace).

  • Related