Ban*_*ana 3 jenkins jenkins-pipeline jenkins-shared-libraries
我想添加扩展在 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')
}
}
Run Code Online (Sandbox Code Playgroud)
我的 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')
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点 ?如何为继承定义附加参数?
谢谢
我们在 /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
}
Run Code Online (Sandbox Code Playgroud)
然后在您的 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)
])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1520 次 |
| 最近记录: |