gpt4 book ai didi

jenkins - Jenkins 共享库中的全局变量

转载 作者:行者123 更新时间:2023-12-04 12:42:02 25 4
gpt4 key购买 nike

我有一个使用共享库的 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_nameenv[param_name] 跨共享库访问

关于jenkins - Jenkins 共享库中的全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57688110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com