【发布时间】:2019-08-28 08:31:30
【问题描述】:
我有一个使用共享库的 Jenkinsfile。我想创建一个可在共享库的所有函数中使用的全局变量,类似于params 对象。但是我总是以
groovy.lang.MissingPropertyException: No such property: pipelineParams for class: groovy.lang.Binding
在this guideline 之后,我在Jenkinsfile 中定义了一个Field:
import org.apache.commons.io.FileUtils
@groovy.transform.Field
def pipelineParams
library identifier: 'pipeline-helper@master', retriever: modernSCM(
[$class: 'GitSCMSource',
remote: 'https://bitbucket/scm/jenkins/pipeline-helper.git',
credentialsId: 'bitbucket.service.user'
])
defaultCiPipelineMSBuild {
nodes = 'TEST-NODES' /* label of jenkins nodes*/
email = 'example@example.com' /* group mail for notifications */
msbuild = 'MSBUILD-DOTNET-4.6' /* ms build tool to use */
}
然后在defaultCiPipelineMSBuild我设置pipelineParams
def call(body) {
// evaluate the body block, and collect configuration into the object
pipelineParams= [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = pipelineParams
body()
pipeline {
...
稍后我会调用一个函数buildApplication 来使用该变量:
def msBuildExe = tool pipelineParams.msbuild
【问题讨论】:
标签: jenkins groovy jenkins-pipeline