如何在Jenkins管道中传递选择参数来调用作业 [英] How to pass choice parameter to call a job inside jenkins pipeline

查看:463
本文介绍了如何在Jenkins管道中传递选择参数来调用作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jenkins管道的stage内部调用时,如何为下游作业传递choice parameters?

How can I pass choice parameters for the downstream job when called inside a stage in the jenkins pipeline?

我尝试了以下解决方案,但没有用:

I tried the below solutions but none worked:

stage('build job') {
    steps{
        script{
              build job: 'test',
                   parameters: [
                                choice(choices: "option1\noption2\noption3\n", description: '', name: 'choiceParam')
                                ] 
              }
     }
}

出现java.lang.UnsupportedOperationException: no known implementation of class hudson.model.ParameterValue is using symbol ‘choice’

也尝试过这些:

 parameters:
   [
     [$class: 'ChoiceParameterValue', name: 'choiceParam', value: "1\n\2\n3\n"],
   ]

出现java.lang.UnsupportedOperationException: no known implementation of class hudson.model.ParameterValue is named ChoiceParameterValue

我实际上想将选择参数作为value传递为build parameter,例如"$ choiceParam",这样我就可以更新jenkins作业配置,而不必始终更新管道脚本中的值

I actually want to pass the choice parameter as a build parameter like "$choiceParam" for value so that I can just update the jenkins job configuration instead of always updating the values in the pipeline script

有人可以帮我吗

谢谢

推荐答案

通过构建"步骤构建作业时,您将开始该作业,因此需要选择"一个值.

When you are building a job via the Build step, you are kicking it off so you need to have "selected" a value.

在这种情况下,您将传递所需的字符串"选择.没有选择列表.即"1"

In this instance you would pass in the desired 'String' choice. Not a list of choices. i.e. "1"

我们创建参数列表,然后将其传递.因此:我们当前的工作具有以下输入参数:

We create our list of params and then pass that in. So: our current job has these input params:

choice(name: 'ENV', choices: product, description: 'Env'),
choice(name: 'ENV_NO', choices: envParams(product), description: 'Env No'),

我们通过设置它们将它们传递给下游:

We pass these downstream by setting them:

List<ParameterValue> newParams = [
    new StringParameterValue('ENV', params.ENV),
    new StringParameterValue('ENV_NO', params.ENV_NO),
]
build(job: "job", parameters: newParams, propagate: false)

这篇关于如何在Jenkins管道中传递选择参数来调用作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆