簡體   English   中英

如何使用groovy腳本訂購Jenkins參數

[英]How to order Jenkins Parameters using groovy script

我正在使用這個 groovy 腳本來參數化 Jenkins 作業:

properties([
    parameters([
        [$class: 'ChoiceParameter',
            choiceType: 'PT_SINGLE_SELECT',
            description: 'Select param1',
            filterLength: 1,
            filterable: false,
            name: 'param1',
            randomName: 'choice-parameter-5631314439613978',
            script: [
                $class: 'GroovyScript',
                fallbackScript: [
                    classpath: [],
                    sandbox: true,
                    script:
                        'return[\'Could not get param1\']'
                ],
                script: [
                    classpath: [],
                    sandbox: true,
                    script:
                        'return["value1", "value2", "value3"]'
                ]
            ]
        ],
        [$class: 'CascadeChoiceParameter',
            choiceType: 'PT_SINGLE_SELECT',
            description: 'Select param3',
            filterLength: 1,
            filterable: false,
            name: 'param3',
            randomName: 'choice-parameter-10000000000000000',
            referencedParameters: 'param1',
            script: [
                $class: 'GroovyScript',
                fallbackScript: [
                    classpath: [],
                    sandbox: true,
                    script:
                        'return[\'Could not get param3\']'
                ],
                script: [
                    classpath: [],
                    sandbox: true,
                    script:
                        ''' if (param1.equalsIgnoreCase('value1')){
                                return["1", "2"]
                            }
                            else if(param1.equalsIgnoreCase("value2")){
                                return["3", "4"]
                            }
                            else if(param1.equalsIgnoreCase("value3")){
                                return["5", "6"]
                            }
                        '''
                ]
            ]
        ]
    ])
])

pipeline {
  agent any
      parameters {
        string(name: "param2", defaultValue: "test1", description: "Test value")
    }
  stages {
      stage ("Example") {
        steps {
         script{
          echo 'Hello'
        }
        }
      }
  }
}

如果我按原樣使用此腳本,在 Jenkins 作業中,參數將按以下順序顯示:param2、param1、param3。 我真正想要的是按以下順序排列它們:param1、param2、param3。

從代碼中可以看出,對於參數 1 和 3,我使用的是主動選擇參數和主動選擇反應參數,它們取決於在參數 1 中選擇的值。 對於 param2,我需要它作為字符串。

有沒有辦法實現這一點,讓它們按以下順序排列:param1、param2、param3?

好的,我發現我也可以在屬性中使用它:

[$class: 'StringParameterDefinition',
    description: 'Enter param2',
    name: 'param2',
    defaultValue: '',
    randomName: 'string-parameter-1343433232',
    trim: true
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM