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

Usage of jenkinsfile functions in ActiveChoicePlugin

XMLWordPrintable

      I have the following function declared in my Jenkinsfile

      /**
       * returns all available bitbucket projects
       * @return  list of projects
       */
      def java.util.List getBitbucketProjects() {
          echo("[INFO] Get all bitbucket projects")
          String url = "${bitbucketHost}/projects/"
          String response = this.queryBitbucket(url)
          def list = new JsonSlurper().parseText(response)    
          def projects = []
          list.values.each { 
              projects.add(it.key)
          }
          return projects
      }
      

      Now I want to use this in the active choice plugin, so I declare this

      ...
              [$class: 'ChoiceParameter', 
                  choiceType: 'PT_SINGLE_SELECT', 
                  description: 'Select Bitbucket project from Dropdown List', 
                  filterLength: 1, 
                  filterable: true,
                  name: 'project', 
                  script: [
                      $class: 'GroovyScript', 
                      fallbackScript: [
                          classpath: [], 
                          sandbox: false, 
                          script: 
                          """
                             return [ "Could not get bitbucket projects" ]
                          """
                          ], 
                      script: [
                          classpath: [], 
                          sandbox: false, 
                          script: 
                          """
                              return this.getBitbucketProjects()
                          """
                      ]
                  ]
              ], 
      ...
      

      When calling the pipeline, the script always uses the fallback script

      So is this even possible what I try to achieve? if yes, what do I miss here?

       

            kinow Bruno P. Kinoshita
            papanito papanito
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: