0

Because I couldn't use an environment variable that I thought should exist, I printed all the environment variables in my Jenkins Pipeline script:

node { for(e in env) { print "key = ${e.key}, value = ${e.value}" } } 

This prints:

key = null, value = null

I'm very surprised by this.

Why are there no environment variables?

8
  • maybe it's just not iterable? or just another side-effect of CPS. Try sh "set". Commented Feb 9, 2017 at 15:27
  • sh doesn't work: nohup: failed to run command "sh": No such file or directory Commented Feb 9, 2017 at 15:34
  • 1
    What OS is the node running? Commented Feb 9, 2017 at 15:41
  • Red Hat Linux. /bin/sh doesn't work either Commented Feb 9, 2017 at 15:41
  • 2
    no.. that's not a command, it's part of the DSL. use node { sh "set" }. Commented Feb 9, 2017 at 16:01

1 Answer 1

1

Seems to be a bug/limitation. If you look at the implementation, there is no support for iteration.

The following works as a workaround:

node { for(e in env.getEnvironment()) { print "key = ${e.key}, value = ${e.value}" } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.