Accessing Jenkins global property in Groovy

后端 未结 4 1523
死守一世寂寞
死守一世寂寞 2021-02-10 18:20

At this moment I defined a environment variable called GLOBAL_VAR with the value \'test\' under Manage Jenkins -> Configure System -> Global Properties. I have a shell script wh

4条回答
  •  半阙折子戏
    2021-02-10 19:11

    Here is an example of some working code:

    import jenkins.model.*
    nodes = Jenkins.instance.globalNodeProperties
    nodes.getAll(hudson.slaves.EnvironmentVariablesNodeProperty.class)
    envVars = nodes[0].envVars
    envVars['MY_GLOBAL_PROPERTY']
    

    Sources of my solution:

    https://gist.github.com/johnyzed/2af71090419af2b20c5a

    http://pghalliday.com/jenkins/groovy/sonar/chef/configuration/management/2014/09/21/some-useful-jenkins-groovy-scripts.html

    Note to the "hard core" moderator that deleted my previous answer: I have spent quite a few hours searching on the Internet before finding the right solution, you shouldn't delete posts without knowing what is it really talking about. I find such behavior rather discouraging :(

提交回复
热议问题