Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63282

Jenkins dynamic declarative pipeline parameters

    Details

    • Similar Issues:

      Description

      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? 

        Attachments

          Issue Links

            Activity

            Hide
            kinow Bruno P. Kinoshita added a comment -

            Hi stam nick

            The code was originally written for the FreeStyle jobs. Its relies heavily on the HTML/DOM of the parameters.

            We have been getting lots of requests to support pipelines, however, the main block for me is finding time to focus on this task.

            I've heard from users who were able to use the plug-in, but I am not sure how that works, and have never tried it.

            Will close as duplicate of the issue for Pipelines, feel free to subscribe there for updates. Normally I have spare time around holidays in New Zealand (October there's one, then x-mas), and pretty much always use it to work on OSS projects, including this plug-in.

            But should there's a PR before that, I will review and release asap.

            Cheers
            Bruno

            Show
            kinow Bruno P. Kinoshita added a comment - Hi stam nick The code was originally written for the FreeStyle jobs. Its relies heavily on the HTML/DOM of the parameters. We have been getting lots of requests to support pipelines, however, the main block for me is finding time to focus on this task. I've heard from users who were able to use the plug-in, but I am not sure how that works, and have never tried it. Will close as duplicate of the issue for Pipelines, feel free to subscribe there for updates. Normally I have spare time around holidays in New Zealand (October there's one, then x-mas), and pretty much always use it to work on OSS projects, including this plug-in. But should there's a PR before that, I will review and release asap. Cheers Bruno
            Hide
            kinow Bruno P. Kinoshita added a comment -

            Moving work to JENKINS-63284. This way it will be easier for me to triage issues, and keep track of requests for pipelines (this issue will be linked).

            Show
            kinow Bruno P. Kinoshita added a comment - Moving work to JENKINS-63284 . This way it will be easier for me to triage issues, and keep track of requests for pipelines (this issue will be linked).

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: