简体   繁体   English

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

[英]How can I define additional parameters in jenkinsfile who inherit from a pipeline shared lib?

I would like to add a possibility to extends the global parameters define in a Jenkins pipeline. 我想添加一种可能性来扩展Jenkins管道中定义的全局参数。 Each JenkinsFile who call the default pipeline have default parameters and he as able to define parameters himself like this: 每个调用默认管道的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')
            }

}

my generic_pipeline is define in a shared lib generic_pipeline.groovy and they have already default parameters like this: 我的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')
        }
    }
}

How can I do that ? 我怎样才能做到这一点 ? how can I define additional parameters for the inheritances ? 如何为继承定义其他参数?

Thank you 谢谢

We have a separate jobParams.groovy under /vars that sets common params 我们在/ 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
}

Then in your Jenkinsfile, just concatenate the list with the specifics: 然后在您的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)
    ])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在继承自管道共享库的声明性 jenkins 管道中定义其他参数? - How can I define additional parameters in a declarative jenkins pipeline who inherit from a pipeline shared library? 如何在 Jenkinsfile 中包含的 groovy 脚本中定义管道? - How can I define a pipeline in a groovy script included from a Jenkinsfile? 如何使用Pipeline引用Jenkinsfile目录? - How can I reference the Jenkinsfile directory, with Pipeline? 如何在 jenkinsfile 中定义和使用函数? - How can i define and use functions in jenkinsfile? 如何从 jenkins 管道脚本访问共享库中定义的参数列表值? - How to access parameters List values defined in shared lib from jenkins pipeline script? 将“使用参数构建”从管道中的scm传递给Jenkinsfile - Passing 'build with parameters' to Jenkinsfile from scm in pipeline 如何在声明式管道(Jenkinsfile)中配置动态参数? - How to configure dynamic parameters in declarative pipeline (Jenkinsfile)? 将参数从Jenkinsfile传递到共享库 - Passing parameters from Jenkinsfile to a shared library 如何从没有jenkinsfile的存储库触发Jenkins管道构建? - How can I have a Jenkins pipeline build be triggered from a repository with no jenkinsfile? 如何使用 GitHub Org 插件从 jenkins 管道(jenkinsfile)触发另一个作业? - How can I trigger another job from a jenkins pipeline (jenkinsfile) with GitHub Org Plugin?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM