Jenkins Global environment variables in Jenkinsfile

后端 未结 5 1176
深忆病人
深忆病人 2021-02-05 06:17

How do I invoke Global environment variables in Jenkinsfile?
For example, if I have a variable -

 name:credentialsId 
 value:xxxx-xxxx-xxxxx-xxxxxxxxx
         


        
5条回答
  •  自闭症患者
    2021-02-05 06:44

    Scripted pipeline To read an environment variable whose name you know, use env.NAME

    To read an environment variable whose name is not known until runtime use env.getProperty(name).

    For example, a value from a YAML config file represents an environment variable name:

    config.yaml (in workspace)

    myconfig:
      key: JOB_DISPLAY_URL
    

    Jenkinsfile

    node {
        println("Running job ${env.JOB_NAME}")
        def config = readYaml(file:'config.yaml')
        def value = env.getProperty(config.myconfig.key)
        println("Value of property ${config.myconfig.key} is ${value}")
    }
    

提交回复
热议问题