Jenkins Global environment variables in Jenkinsfile

后端 未结 5 1130
深忆病人
深忆病人 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:42

    In a Jenkinsfile, you have the "Working with the Environment" which mentions:

    The full list of environment variables accessible from within Jenkins Pipeline is documented at localhost:8080/pipeline-syntax/globals#env,

    The syntax is ${env.xxx} as in:

    node {
        echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
    }
    

    See also "Managing the Environment".

    How can I pass the Global variables to the Jenkinsfile?
    When I say Global variables - I mean in

    Jenkins -> Manage Jenkins -> Configure System -> Global properties -> Environment variables
    

    See "Setting environment variables"

    Setting an environment variable within a Jenkins Pipeline can be done with the withEnv step, which allows overriding specified environment variables for a given block of Pipeline Script, for example:

    Jenkinsfile (Pipeline Script)

    node {
        /* .. snip .. */
        withEnv(["NAME=value"]) {
            ... your job
        }
    }
    

提交回复
热议问题