Jenkinsfile_定义全局全量

一.通过def定义全局变量

注意:首行def定义的变量不能使用=赋值。

def var
pipeline {
    agent any
    stages {
        stage("定义var") {
           steps {
               script {
                echo var
                var = "test"
               }
           }
        }
        stage("打印var") {
           steps {
              script {
                  echo var
              }
           }
        }
    }
}

二.在script中定义全局全量

pipeline {
    agent any
    stages {
        stage("定义var") {
           steps {
               script {
                var = "test"
                echo var
               }
           }
        }
        stage("打印var") {
           steps {
              script {
                  echo var
              }
           }
        }
    }
}
posted @ 2020-08-06 19:33  yuhaohao  阅读(2181)  评论(0编辑  收藏  举报