Jenkinsfile中的动态参数?

mat*_*sev 9 jenkins jenkins-pipeline

如何在一个?中使用Jenkins Dynamic PluginJenkinsfile

我正在寻找的是一个Jenkinsfile片段:

  • 启用Build with ParametersJenkins作业中的选项
  • 选中后,将填充填充可以使用的列表的脚本,Dynamic Choice Parameters并且用户将看到下拉列表.

尝试时:

  1. Pipeline syntax 在詹金斯编辑
  2. 选择properties: Set job propertiesSample step
  3. 选择 This project is parameterized
  4. 运用 Dynamic Choice Parameter
  5. 输入值Name,Choice Script,Remote Script
  6. Generate Pipeline Script

我得到以下模板:

properties([
    parameters([
        <object of type com.seitenbau.jenkins.plugins.dynamicparameter.ChoiceParameterDefinition>
    ]), 
    pipelineTriggers([])
])
Run Code Online (Sandbox Code Playgroud)

即生成的管道脚本不包含我在5.上面步骤中输入的数据.如何修改parameters以便用户可以看到参数名称,选项等?


Jenkins版本:2.19.3动态参数插件版本:0.2.0

小智 7

Jenkins Dynamic Plugin已经不再需要了.只需使用普通选择或字符串参数,并通过groovy代码更新值.

#!/bin/groovy

def envs = loadEnvs();

properties([
   parameters([
      choice(choices: envs, description: 'Please select an environment', name: 'Env')
   ])
])

node { 
   try {
      stage('Preparation'){
...
Run Code Online (Sandbox Code Playgroud)

如果使用choice参数,请注意必须提供一个字符串,其中值由新行分隔.

例如:

"a\nb\nc"
Run Code Online (Sandbox Code Playgroud)

如果你真的需要插件,那么就这个问题投票JENKINS-42149.

  • 这个问题是构建属性的更改只影响_future_ builds - 更改当前构建的参数没有帮助,因为`properties()`函数在用户已经为该构建提供构建参数后运行 (10认同)
  • 这是一个脚本化的管道。它在声明式管道中工作吗?如果是这样,怎么办?语法是什么? (2认同)