How to get environment variable in Jenkins Groovy script console?

后端 未结 2 1876
伪装坚强ぢ
伪装坚强ぢ 2020-12-17 17:31

In Jenkins configuration (http://JenkinsURL/configure) within \"Global properties\" I defined some \"Environment variables\".

How can I access them in the Groovy Scr

相关标签:
2条回答
  • 2020-12-17 18:11

    You can get global properties like this:

    import jenkins.model.Jenkins
    def envVars = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars() 
    println envVars['myVar']
    

    I referred to the link below, about how to set global properties programatically. https://groups.google.com/forum/#!topic/jenkinsci-users/KgCGuDmED1Q

    0 讨论(0)
  • 2020-12-17 18:11

    You can use System to get environment variables.

    def env = System.getenv()
    println(env['JENKINS_HOME'])
    

    (See also http://@myJenkHostname@/env-vars.html (where @myJenkHostname@ is your Jenkins hostname) for a list of built-in environment variables.)

    0 讨论(0)
提交回复
热议问题