Ale*_*nov 3 groovy jenkins jenkins-pipeline
基本上,没有多余的废话,我无法将构建属性传递给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不太满意,所以可能很明显。
一个小的解决方法是使用地图而不是闭包:
tc_test ([
repo: 'test1',
folder: 'test2',
submodules: true,
refs = params.GitCheckout
])
Run Code Online (Sandbox Code Playgroud)
可能有缺点,但是对我来说效果很好。
仍然必须将params作为参数来访问它们,但是至少现在代码更有意义了。
| 归档时间: |
|
| 查看次数: |
5097 次 |
| 最近记录: |