如何在Jenkins管道脚本中使用扩展选择参数插件?

Spa*_*gen 23 jenkins extended-choice-parameter

扩展选择参数插件很棒,我在通过UI配置的作业中使用它https://wiki.jenkins-ci.org/display/JENKINS/Extended+Choice+Parameter+plugin

但是,我正努力让它在Jenkinsfile样式管道脚本中运行.由于Jenkins管道语法生成器创建了以下代码段,因此扩展选择参数插件似乎尚未与管道脚本完全兼容:

parameters([<object of type com.cwctravel.hudson.plugins.extended_choice_parameter.ExtendedChoiceParameterDefinition>])
Run Code Online (Sandbox Code Playgroud)

如果我手动创建参数,我会得到与https://issues.jenkins-ci.org/browse/JENKINS-32188中提到的相同的行为

org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class 
Run Code Online (Sandbox Code Playgroud)

有没有人知道可以解决ExtendedChoiceParameterDefinition不使用问题的任何变通办法@DataBoundConstructor

  • 詹金斯2.19.2
  • 扩展选择参数插件0.75

Dev*_*ine 10

自2019年4月2日以来,由于此提交,现在成为可能:https//github.com/jenkinsci/extended-choice-parameter-plugin/pull/25

您可以像这样使用它:

properties([
    parameters([
        extendedChoice( 
            name: 'PROJECT', 
            defaultValue: '', 
            description: 'Sélectionnez le projet à construire.', 
            type: 'PT_SINGLE_SELECT', 
            groovyScript: valueKeysScript,
            descriptionGroovyScript: valueNamesScript
        )
    ])
])
Run Code Online (Sandbox Code Playgroud)

如果您想知道每个可能的参数,则必须参考源代码。如果您想知道“ type”键的每个可能值,请查看这些PT_*常量


小智 6

这是我对此pb的解决方法:

https://gist.github.com/jgraglia/44a7443847cff6f0d87387a46c7bb82f

即:通过声明所有args手动实例化参数

我可以用我的管道添加一个多清单参数.


ahm*_*ish 6

导航到您的http://jenkins-url.com/pipeline-syntax

在示例步骤下拉列表中选择“属性:设置作业属性”

有一个“此项目已参数化”复选框,然后您可以选择“添加参数”>“扩展选择参数”。在那里添加菜单项,然后单击“生成管道脚本”进行转换。

修剪它,以便删除之前的 'properties([parameters([' before 和 '])])' 之后:

extendedChoice(defaultValue: 'whatif', description: 'Run as what if?', multiSelectDelimiter: ',', name: 'whatif', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_SINGLE_SELECT', value: 'whatif, LIVE', visibleItemCount: 2)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 如果您的 Jenkins 服务器是端口 12345 上的 10.10.10.10,则 URL 为 10.10.10.10:12345/pipeline-syntax 然后,在示例步骤下拉列表中选择“属性:设置作业属性”。有一个“此项目已参数化”复选框,然后您可以选择“添加参数”&gt;“扩展选择参数”。然后单击“生成管道脚本”进行转换。 (2认同)