我有一个使用共享库的 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
最佳答案
您没有尝试自己创建一个全新的管道参数,而是尝试将您的变量添加到您可以在共享库中使用的已经可用的 env
参数中吗?
env.param_name = "As per your requirement"
也可以通过env.param_name
或env[param_name]
跨共享库访问
关于jenkins - Jenkins 共享库中的全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57688110/