pap*_*ito 5 groovy jenkins jenkins-pipeline
我有一个使用共享库的 Jenkinsfile。我想创建一个可在共享库的所有函数中使用的全局变量,类似于对象params。然而我总是最终得到
groovy.lang.MissingPropertyException: No such property: pipelineParams for class: groovy.lang.Binding
Run Code Online (Sandbox Code Playgroud)
遵循此准则,我Field在以下位置定义 a Jenkinsfile:
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 */
}
Run Code Online (Sandbox Code Playgroud)
然后在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 {
...
Run Code Online (Sandbox Code Playgroud)
后来我调用一个buildApplication想要使用该变量的函数:
def msBuildExe = tool pipelineParams.msbuild
Run Code Online (Sandbox Code Playgroud)
env您是否尝试将变量添加到可以在共享库中使用的可用参数中,而不是自己创建一个全新的管道参数?
env.param_name = "As per your requirement"
Run Code Online (Sandbox Code Playgroud)
还可以通过共享库进行访问env.param_name或env[param_name]跨共享库进行访问
| 归档时间: |
|
| 查看次数: |
10592 次 |
| 最近记录: |