1

I want to use a global variable that I have created in my Jenkins Configuration as follow:

enter image description here

My question is: How can I use it in my Pipeline(aka workflow) job? I'm doing something like:

enter image description here

When I ran it, It displayed:

[Pipeline] node
Running on master in /opt/devops/jenkins_home/jobs/siman/jobs/java/jobs/demo-job/workspace
[Pipeline] {
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: PRODUCTION_MAILS for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:224)

Instead If I create a "Free Style Project" I can use the global property as follow without problems:

enter image description here

When I ran it, it display the value if I do some "echo" as follow:

enter image description here

CSchulz
  • 10,882
  • 11
  • 60
  • 114
Daniel Hernández
  • 4,078
  • 6
  • 27
  • 38

2 Answers2

2

This is how I achieved it:

node('master') {
    echo "${env.PRODUCTION_MAILS}"
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Daniel Hernández
  • 4,078
  • 6
  • 27
  • 38
-2

Or You could use

echo "This is the value: " + PRODUCTION_MAILS

That should work.

SamK
  • 53
  • 6