具有扩展选择参数的 Jenkins 声明式管道 [英] Jenkins Declarative Pipeline with extended choice parameter
问题描述
我尝试使用 Jenkins 实现我的第一个声明式管道,以便能够将作业的参数定义也放在 SCM 下.
I tried out to implement my first Declarative Pipeline with Jenkins to be able to put also the parameter definitions of a job under SCM.
我想转移具有扩展选择参数的现有工作.不幸的是,我无法将其添加到脚本的参数{...} 部分.
I wanted to transfer an existing job that has an extended choice paraemter. Unfortunately I was not able to add it to the parameters{...} section of my script.
在插件页面上:https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin 我发现一条评论说应该可以通过:
On the plugin page: https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin I found a comment that stated it should be possible by:
import com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition
def type = "PT_JSON"
def groovyScript = null
def propertyValue = null
def projectName = null
def propertyFile = null
def groovyScriptFile = "/path_to/script.groovy"
...
def extendedChoice = new ExtendedChoiceParameterDefinition(name,
type,
propertyValue,
projectName,
propertyFile,
groovyScript,
.....
input message: 'Param1', parameters: [extendedChoice]
不幸的是,这对我不起作用.输入请求"给出了一个未指定的错误.虽然我可以接受输入消息"解决方案,但这并不是我首先要寻找的.如前所述,我想将此参数添加到参数部分.但我找不到任何描述这一点的地方.任何建议如何继续,或者可能还有替代方法/插件?
Unfortunately this was not working for me. "input Requested" gave a non specified error. While I could live with an "input message" solution, it was not what I was looking for in the first place. I want to add this parameter to the parameter section as mentioned already. But I am not able to find any place where this is described. Any suggestions how to go on, or maybe also alternative approaches/plugins?
推荐答案
这是我使用并成功测试的 Single 参数,您可能需要将其转换为 Json
This is what i used and Tested sucessfully for Single parameter you might need to convert it for Json
com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition extch =new com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition( "NAME", "PT_SINGLE_SELECT", "VALUE, a, b", null, null, null, null, null,null, null,null,null, null, null, null,null, null, null,null, null, null, null, null, null, null,null,false,false,2,"DESC", "," )
这篇关于具有扩展选择参数的 Jenkins 声明式管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!