Jenkins EnvInject plugin + Pipeline job

回眸只為那壹抹淺笑 提交于 2019-12-19 07:10:28

问题


I would like to use EnvInject plugin within my pipeline job. So, I have a possibility to set checkbox "Prepare an environment for the run", but there is no action "Inject environment variables", like in freestyle job. I declared my variables in "Properties Content" block:

How to inject environment variables in pipeline job using EnvInject?


回答1:


If you declared following variables in "Properties Content" block:

param1=value1
param2=value2

Then you can get them into pipeline here so:

//do something
def par1 = env.param1
def par2 = env.param2



回答2:


Here an example as a complete Jenkins pipeline script:

pipeline {
    agent any
    stages {
        stage('Test') {
            steps {
                // use environment variable as parameter to predefined steps
                echo "These are my parameters: '${env.param}'"

                // use environment variable in a Groovy script block
                script {
                    def par = env.param
                    println "parameter values: '${par}'"
                }
            }
        }
    }
}


来源:https://stackoverflow.com/questions/37917471/jenkins-envinject-plugin-pipeline-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!