gpt4 book ai didi

jenkins - 如何在继承自管道共享库的 jenkinsfile 中定义其他参数?

转载 作者:行者123 更新时间:2023-12-01 11:15:53 26 4
gpt4 key购买 nike

我想增加一种扩展 Jenkins 管道中定义的全局参数的可能性。每个调用默认管道的 JenkinsFile 都有默认参数,他可以自己定义参数,如下所示:

@Library('mylib') _ 
generic_pipeline {

parameters {
choice(choices: namespaces, description: 'namespaces ?', name: 'namespaceIdChoice')
string(defaultValue: "$BRANCH_NAME-$BUILD_NUMBER", description: 'What is the project name ?', name: 'projectName')
}

}

我的 generic_pipeline 在共享库 generic_pipeline.groovy 中定义他们已经有这样的默认参数:

def call(Closure body) {
def params = [:]
body.resolveStrategy = Closure.DELEGATE_FIRST
body.delegate = params
body()


pipeline {

agent {
label 'master'
}

parameters {
string(defaultValue: "defaultParam2", description: 'What is defaultParam2 ?', name: 'defaultParam2')
}
}
}

我该怎么做?如何为继承定义附加参数?

谢谢

最佳答案

我们在/vars 下有一个单独的 jobParams.groovy 来设置通用参数

List commonParams() {
//return list of parameters
def paramsList = [
choice(name: 'ACCOUNT_NAME', choices: ['account1', 'account2'].join('\n'), description: 'Account Name'),
choice(name: 'AWS_REGION', choices: PipelineUtils.regions.join('\n'), description: 'AWS Region to build/deploy'),
]

return paramsList
}

然后在您的 Jenkinsfile 中,将列表与具体内容连接起来:

List commonParams = jobParams.commonParams()
properties([
buildDiscarder(logRotator(numToKeepStr: '20')),
parameters([
choice(name: 'MY_SPECIFIC_PARAM', choices: ['1', '2', '3'].join('\n'), description: ''),
choice(name: 'PARAM2', choices: ['value'].join('\n'), description: ''),
] + commonParams)
])

关于jenkins - 如何在继承自管道共享库的 jenkinsfile 中定义其他参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51382761/

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