Environment variable in Jenkins Pipeline

后端 未结 2 1881
半阙折子戏
半阙折子戏 2021-02-01 14:19

Is there any environment variable available for getting the Jenkins Pipeline Title?

I know we can use $JOB_NAME to get title for a freestyle job, but is th

相关标签:
2条回答
  • 2021-02-01 14:33

    To avoid problems of side effects after changing env, especially using multiple nodes, it is better to set a temporary context.

    One safe way to alter the environment is:

     withEnv(['MYTOOL_HOME=/usr/local/mytool']) {
        sh '$MYTOOL_HOME/bin/start'
     }
    

    This approach does not poison the env after the command execution.

    0 讨论(0)
  • 2021-02-01 14:37

    You can access the same environment variables from groovy using the same names (e.g. JOB_NAME or env.JOB_NAME).

    From the documentation:

    Environment variables are accessible from Groovy code as env.VARNAME or simply as VARNAME. You can write to such properties as well (only using the env. prefix):

    env.MYTOOL_VERSION = '1.33'
    node {
      sh '/usr/local/mytool-$MYTOOL_VERSION/bin/start'
    }
    

    These definitions will also be available via the REST API during the build or after its completion, and from upstream Pipeline builds using the build step.

    For the rest of the documentation, click the "Pipeline Syntax" link from any Pipeline job

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