Search code examples
jenkinsjenkins-pipelinejenkins-2

Usage of Global property in Pipeline job


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


Solution

  • This is how I achieved it:

    node('master') {
        echo "${env.PRODUCTION_MAILS}"
    }