How to set Jenkins Declarative Pipeline environments with Global Variables?

三世轮回 提交于 2019-12-04 20:41:33

I think you should use:

steps {
  echo "${env.LOCAL_BUILD_PATH}"
}

as in "environment" step you're defining environmental variables which are later accessible by env.your-variable-name

So this is method that I ended up using

pipeline {
    agent {
        label 'master'
    }

    stages {
        stage ("Setting Variables"){
            steps {
                script{        
                    LOCAL_BUILD_PATH = "$env.WORKSPACE/build"
                }
            }
        }

        stage('Print Varliabe'){
            steps{
                echo LOCAL_BUILD_PATH
            }
        }
    }
}         

This a scope issue. Declare the variable, at the top and set it to null. Something like

def var = null

You should be able to set the value in a block/closure/stage and access it in another

Hem

You can use something like this...

LOCAL_BUILD_PATH="${env.WORKSPACE}/build/"  

Remember: use "(double quote) for variable in string

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