dawn-liu

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
pipeline{ 
    
    agent any
    environment{    //定义全局变量
        is_smoke = true
        full_test= false
    }
    stages{
        
        stage("first") {
            steps {
                script {
                    println "test1......"
                    full_test =  true    //改变全局变量的值
                }
            }
        }

        stage("yanzheng") {
            when {
                expression {
                    return (full_test == true) //条件判断
                }
            }
            steps {
                script {
                    println full_test  //打印为true
                    println "SMOKE TEST: check service startup"
                }
            }
        }
    }
}

 使用withEnv,用途在于单独设置运行时的环境,比如 java环境,变量与其他步骤不同等等

pipeline{ 
    
    agent any
    environment{    //定义全局变量
        is_smoke = true
        full_test= false
    }
    stages{
        
        stage("first") {
            steps {
                script {
                    println "测试全局变量的值"
                    println full_test   //全局变量的值,打印为false
                }
            }
        }

        stage("yanzheng") {
            steps {
                withEnv(['full_test=true']){
                script {
                    println 'withEnv的情况'
                    println full_test  //打印为true
                    println "SMOKE TEST: check service startup"
                }
            }}
        }
    }
}

 

posted on 2019-09-18 14:03  dawn-liu  阅读(586)  评论(0编辑  收藏  举报