具有相关参数的参数化Jenkins作业

时间:2018-08-14 15:34:26

标签: jenkins

我正在尝试创建具有相关参数的Jenkins作业。

首先,我希望能够选择一个主要参数:enter image description here 其次,能够从一组选项中进行选择,这些选项是主参数的从属参数。 enter image description here

如果我选择其他主要参数:enter image description here

然后,我想拥有另一组选项作为对第二个主要参数的依赖。 enter image description here

请,您能帮我实现这一目标吗?

1 个答案:

答案 0 :(得分:1)

我建议使用Active Choices plugin(也称为“ uno-choice”)。 (This questionreferences的范围是both,尽管它们不是公认的答案。)

对于您的特定用例,您需要在工作中添加两个参数:

  1. 有效选择参数

    • 名称:MainOption
    • 脚本:Groovy脚本

      return ['A','B']
      
  2. 活动选择的活动参数

    • 名称:DependentOption
    • 脚本:Groovy脚本

      def choices
      switch(MainOption){
          case 'A':
              choices = ['Blue','Green','Yellow']
              break
          case 'B':
              choices = ['Black','White','Grey']
              break
          default:
              choices = ['N/A']
              break
      }
      return choices
      
    • Fallback脚本:Groovy脚本

      return ['Option error']
      
    • 参考参数

      MainOption
      

“参考参数”设置是关键-更改该值时,插件将重新评估Groovy脚本,从而为您提供从属参数效果。

相关问题