Jenkinsfile中的奇怪变量作用域行为 [英] Strange variable scoping behavior in Jenkinsfile

查看:104
本文介绍了Jenkinsfile中的奇怪变量作用域行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行以下Jenkins管道脚本时:

When I run the below Jenkins pipeline script:

def some_var = "some value"

def pr() {
    def another_var = "another " + some_var
    echo "${another_var}"
}

pipeline {
    agent any

    stages {
        stage ("Run") {
            steps {
                pr()
            }
        }
    }
}

我收到此错误:

groovy.lang.MissingPropertyException: No such property: some_var for class: groovy.lang.Binding

如果从some_var中删除了def,它将正常工作.有人可以解释导致此行为的作用域规则吗?

If the def is removed from some_var, it works fine. Could someone explain the scoping rules that cause this behavior?

推荐答案

TL; DR

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆