相关疑难解决方法(0)

jenkins管道:无法将构建参数传递给共享库变量

基本上,没有多余的废话,我无法将构建属性传递给Library var调用。

jenkinsfile相关的块:

tc_test{
    repo = 'test1'
    folder = 'test2'
    submodules = true
    refs = params.GitCheckout
}
Run Code Online (Sandbox Code Playgroud)

导致错误

java.lang.NullPointerException:无法在空对象上获取属性'GitCheckout'

但是,这有效:

def a1 = params.GitCheckout
tc_test{
    repo = 'test1'
    folder = 'test2'
    submodules = true
    refs = a1
}
Run Code Online (Sandbox Code Playgroud)

共享库中vars / tc_test.groovy的内容:

def call ( body ) {

    def config = [:]
    body.resolveStrategy = Closure.DELEGATE_FIRST
    body.delegate = config
    try {
        body()
    } catch(e) {
        currentBuild.result = "FAILURE";
        throw e;
    } finally {

        config.each{ k, v -> println "${k}:${v}" }

    }
} …
Run Code Online (Sandbox Code Playgroud)

groovy jenkins jenkins-pipeline

3
推荐指数
1
解决办法
5097
查看次数

标签 统计

groovy ×1

jenkins ×1

jenkins-pipeline ×1