小编Ale*_*lex的帖子

在脚本块的 Jenkinsfile 中使用 def 和不使用 def 有什么区别?

我有两个 Jenkinsfile 作为示例: A_Jenkinsfile 的内容是:

pipeline {
    agent any
    stages {
        stage("first") {
            steps {
                script {
                 foo = "bar"
                }
            sh "echo ${foo}"
            }
        }
        stage("two") {
            steps {
            sh "echo ${foo}"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

另外一个是B_Jenkinsfile,其内容是:

pipeline {
    agent any
    stages {
        stage("first") {
            steps {
                script {
                 def foo = "bar"
                }
            sh "echo ${foo}"
            }
        }
        stage("two") {
            steps {
            sh "echo ${foo}"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我构建它们时,B_Jenkinsfile 失败,A_Jenkinsfile 成功。

在脚本块的 Jenkinsfile 中使用 def 和不使用 def …

pipeline jenkins jenkins-pipeline

0
推荐指数
1
解决办法
677
查看次数

标签 统计

jenkins ×1

jenkins-pipeline ×1

pipeline ×1