Jenkins 选择参数传递给管道作业

编程入门 行业动态 更新时间:2024-10-28 20:19:51
本文介绍了Jenkins 选择参数传递给管道作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

目前我有一个管道作业,它有不同的参数,其中一个参数是选择参数.这是该作业参数的 config.xml 输出:

Currently I have a pipeline job which has different paramters where one of this parameters is a Choice parameter. Here is the config.xml output of that job parameter:

<hudson.model.ChoiceParameterDefinition> <choices class="java.util.Arrays$ArrayList"> <a class="string-array"> <string>f1</string> <string>f2</string> <string>f3</string> <string>f4</string> </a> </choices> <name>WHERE</name> <description>Something</description> </hudson.model.ChoiceParameterDefinition>

现在我可以通过传递字符串参数从管道中调用此作业:

Now I can call this job from a pipeline via by passing a string parameter:

build job: "NameOfTheJob"", parameters: [ [$class: 'StringParameterValue', name: 'BRANCH', value: "${BRANCH}"], ]

但我无法为选择参数定义参数:

But I couldn't get a way to define the parameters for a choice parameter:

我尝试了以下方法:

build job: "NameOfTheJob"", parameters: [ [$class: 'StringParameterValue', name: 'BRANCH', value: "${BRANCH}"], [$class: 'ChoiceParameterValue', name: 'WHERE', value: 'F3'], ]

但这失败并出现以下错误:

But this failed with the following error:

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

所以问题是:如何在调用其他管道作业时定义选择参数:

So the question is: How to define a choice parameters in calling an other pipeline job:

build job: "NameOfTheJob"", parameters: [ [$class: 'StringParameterValue', name: 'BRANCH', value: "${BRANCH}"], [$class: '??????', ????], ]

有人有这样的例子吗?

推荐答案

我看过一个使用以下语法的工作示例:

I have seen a working example that uses the below syntax:

build job:'NameOfTheJob', parameters: [ string(name: 'FirstOption', value: "test"), string(name: 'AnotherOption', value: "test12") ]

基本上,不要以特殊的方式对待选择参数,只需将它们视为常规字符串参数即可.

Basically, don't treat the choice parameters in a special manner, just treat them as regular string parameters.

更多推荐

Jenkins 选择参数传递给管道作业

本文发布于:2023-07-07 04:42:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058903.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:作业   管道   参数   Jenkins

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!