2017-04-14 51 views
2

我使用的是主動選擇無參考參數插件在DSL工作在這裏的代碼主動選擇無參考參數在詹金斯管道

parameters { 
        activeChoiceParam('choice1') { 
         description('select your choice') 
         choiceType('RADIO') 
         groovyScript { 
          script("return['aaa','bbb']") 
          fallbackScript('return ["error"]') 
         } 
        } 
        activeChoiceReactiveParam('choice2') { 
         description('select your choice') 
         choiceType('RADIO') 
         groovyScript { 
          script("if(choice1.equals("aaa")){return ['a', 'b']} else {return ['aaaaaa','fffffff']}") 
          fallbackScript('return ["error"]') 
         } 
         referencedParameter('choice1') 
        } 

和它的工作的罰款我現在想的是如何使用activeChoiceReactiveParam在jenkinsFile管道工作我做到了這一點:

properties(
    [ 
      [ 
        $class    : 'ParametersDefinitionProperty', 
        parameterDefinitions: [ 
          [ 
            $class  : 'ChoiceParameterDefinition', 
            choices : 'aaa\nbbb', 
            description: 'select your choice : ', 
            name  : 'choice1' 
          ] 

但我怎麼能添加choice2參數!

回答

3

而不是使用主動選擇無參考參數我這樣做的,它的工作!

node('slave') { 
    def choice1 
    def choice2 

    stage ('Select'){ 
     choice1 = input(id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'aa\nbb', description: '', name: ''] ]) 
     if(choice1.equals("aa")){ 
      choice2 = input(id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'yy\nww', description: '', name: ''] ]) 
     }else{ 
      choice2 = input(id: 'userInput', message: 'Select your choice', parameters: [ [\$class: 'ChoiceParameterDefinition', choices: 'gg\nkk', description: '', name: ''] ]) 
     } 
    } 
} 
0

嘗試類似的東西:

properties(
[ 
     [ 
       $class    : 'ParametersDefinitionProperty', 
       parameterDefinitions: [ 
         [ 
           $class  : 'ChoiceParameterDefinition', 
           choices : 'aaa\nbbb', 
           description: 'select your choice : ', 
           name  : 'choice1' 
         ], 
         [ 
           $class  : 'ChoiceParameterDefinition', 
           choices : 'ccc\nddd', 
           description: 'select another choice : ', 
           name  : 'choice2' 
         ] 
+0

choice2取決於choice1;如果用戶選擇choice1作爲「aaa」而不是選擇2上的選擇將是「cc」或「dd」,並且如果用戶選擇choice1作爲「bbb」而不是選擇2上的選擇將是「ee」或「rr」 – Ibtissam