I want a the choice option values be populated at runtime by a function.
      The following code should to generate a list of options, but for some reason its not working ... 

      def getEnv() {
           return["Dev","Prod"] 
      }
      def getServerByEnvParam(env_param) {
          if (env_param.equals("Dev")){
              return["dev01","dev02"]
          }
          else if(env_param.equals("Prod")){
              return["prd001","prd02"]
          } else {
              return["unknown"]
          }
      }
      properties([
          parameters([
              [$class: 'ChoiceParameter', 
                  choiceType: 'PT_SINGLE_SELECT', 
                  description: 'Select Environment', 
                  name: 'myEnv', 
                  script: [
                      $class: 'GroovyScript', 
                      fallbackScript: [
                          classpath: [], 
                          sandbox: false, 
                          script: 
                              'return[\'myEnv Error\']'
                      ], 
                      script: [
                          classpath: [], 
                          sandbox: false, 
                          script: 
                              'return getEnv()'
                      ]
                  ]
              ], 
              [$class: 'CascadeChoiceParameter', 
                  choiceType: 'PT_SINGLE_SELECT', 
                  description: 'Select Server', 
                  filterable: false, 
                  name: 'myServer', 
                  referencedParameters: 'myEnv', 
                  script: [
                      $class: 'GroovyScript', 
                      fallbackScript: [
                          classpath: [], 
                          sandbox: false, 
                          script: 
                              'return[\'myServer Error\']'
                      ], 
                      script: [
                          classpath: [], 
                          sandbox: false, 
                          script: 
                              'return getServerByEnvParam(myEnv)'
                      ]
                  ]
              ]
          ])
      ])
      pipeline {
          agent any    stages {
              stage('Init') {
                  steps {
                      script{
                          println getServerByEnvParam(myEnv)
                      }
                  }
              }
          }
      }
      

       

      how can I to define and use these functions inside jenkins file? 
      is a pipeline supports dynamic parameters based on function in shared libraries? 

          [JENKINS-63282] Jenkins dynamic declarative pipeline parameters

          stam nick created issue -
          stam nick made changes -
          Description Original: I want a the choice option values be populated at runtime by a function.
          The following code should to generate a list of options, but for some reason its not working ... 


          {code:java}
          def getEnv() {
               return["Dev","Prod"]
          }def getServerByEnvParam(env_param) {
              if (env_param.equals("Dev")){
                  return["dev01","dev02"]
              }
              else if(env_param.equals("Prod")){
                  return["prd001","prd02"]
              } else {
                  return["unknown"]
              }
          }
          properties([
              parameters([
                  [$class: 'ChoiceParameter',
                      choiceType: 'PT_SINGLE_SELECT',
                      description: 'Select Environment',
                      name: 'myEnv',
                      script: [
                          $class: 'GroovyScript',
                          fallbackScript: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return[\'myEnv Error\']'
                          ],
                          script: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return getEnv()'
                          ]
                      ]
                  ],
                  [$class: 'CascadeChoiceParameter',
                      choiceType: 'PT_SINGLE_SELECT',
                      description: 'Select Server',
                      filterable: false,
                      name: 'myServer',
                      referencedParameters: 'myEnv',
                      script: [
                          $class: 'GroovyScript',
                          fallbackScript: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return[\'myServer Error\']'
                          ],
                          script: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return getServerByEnvParam(myEnv)'
                          ]
                      ]
                  ]
              ])
          ])
          pipeline {
              agent any stages {
                  stage('Init') {
                      steps {
                          script{
                              println getServerByEnvParam(myEnv)
                          }
                      }
                  }
              }
          }
          {code}
           

          how can I to define and use functions inside jenkins file ? 
          is a pipeline supports dynamic parameters based on function in shared libraries ? 
          New: I want a the choice option values be populated at runtime by a function.
           The following code should to generate a list of options, but for some reason its not working ... 
          {code:java}
          def getEnv() {
               return["Dev","Prod"]
          }
          def getServerByEnvParam(env_param) {
              if (env_param.equals("Dev")){
                  return["dev01","dev02"]
              }
              else if(env_param.equals("Prod")){
                  return["prd001","prd02"]
              } else {
                  return["unknown"]
              }
          }
          properties([
              parameters([
                  [$class: 'ChoiceParameter',
                      choiceType: 'PT_SINGLE_SELECT',
                      description: 'Select Environment',
                      name: 'myEnv',
                      script: [
                          $class: 'GroovyScript',
                          fallbackScript: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return[\'myEnv Error\']'
                          ],
                          script: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return getEnv()'
                          ]
                      ]
                  ],
                  [$class: 'CascadeChoiceParameter',
                      choiceType: 'PT_SINGLE_SELECT',
                      description: 'Select Server',
                      filterable: false,
                      name: 'myServer',
                      referencedParameters: 'myEnv',
                      script: [
                          $class: 'GroovyScript',
                          fallbackScript: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return[\'myServer Error\']'
                          ],
                          script: [
                              classpath: [],
                              sandbox: false,
                              script:
                                  'return getServerByEnvParam(myEnv)'
                          ]
                      ]
                  ]
              ])
          ])
          pipeline {
              agent any stages {
                  stage('Init') {
                      steps {
                          script{
                              println getServerByEnvParam(myEnv)
                          }
                      }
                  }
              }
          }
          {code}
           

          how can I to define and use these functions inside jenkins file? 
           is a pipeline supports dynamic parameters based on function in shared libraries? 
          Bruno P. Kinoshita made changes -
          Link New: This issue duplicates JENKINS-63284 [ JENKINS-63284 ]
          Bruno P. Kinoshita made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]

            kinow Bruno P. Kinoshita
            stamnik stam nick
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: