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

Cannot use groovyscript in freestyle job with plugin

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Won't Fix
    • Component/s: active-choices-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.249.2
      name: uno-choice version: "2.5.1"
      official docker image jenkins/jenkins:lts
    • Similar Issues:

      Description

      Trying to pull a list of maven artifacts from nexus and I have been stuck on this for a few days and no amount of google searching has helped.
       

      parameters {
         activeChoiceParam('ARTIFACT_VERSION') {
         description('Choose Wisely')
         filterable()
         choiceType('SINGLE_SELECT')
         groovyScript{
           script('''
             def mavendata = new XmlSlurper().parse("''' + jobNexusUrl + '''")
             println mavendata.versioning.versions.version*.text()
             '''
            )
            fallbackScript('"fallback choice"')
          }
        }
      }
      

       
      I get this error when the job is being created by the seedjob.

       

       

      ERROR: (rdrti_app_environment.groovy, line 140) No signature of method: java.lang.String.call() is applicable for argument types: (java.lang.String) values: [ 
      def mavendata = new XmlSlurper().parse("https://nexus.interna.com/nexus/content/repositories/rdrti2-releases/com/rd/rti/rdrti2/maven-metadata.xml")
       println mavendata.versioning.versions.version*.text()
       ]
       Possible solutions: wait(), any(), wait(long), split(java.lang.String), take(int), any(groovy.lang.Closure)
       Finished: FAILURE
      

       
      If i just create a freestyle job in the gui and put in those 2 lines of groovy it works fine

       

       
      Here is a maven metadata example that I tested with
      https://gist.githubusercontent.com/r00t4ccess/14be3e653e8f643e83f3d2ec50b16ef9/raw/afb7a2d5386be58f0ae8057b936bb7514731d2c0/maventest.xml
       
       

       

      def metadata = new XmlSlurper().parse("https://gist.githubusercontent.com/r00t4ccess/14be3e653e8f643e83f3d2ec50b16ef9/raw/afb7a2d5386be58f0ae8057b936bb7514731d2c0/maventest.xml")
      return metadata.versioning.versions.version*.text().reverse()
      

        Attachments

          Activity

          Hide
          kinow Bruno P. Kinoshita added a comment -

          The scripts appear to be missing the return statement. I think they should be something like (note return statements, and fallback returns an array):

          job('generated-1') {
            def jobNexusUrl = 'https://nexus.interna.com/nexus/content/repositories/rdrti2-releases/com/rd/rti/rdrti2/maven-metadata.xml'
            parameters {
               activeChoiceParam('ARTIFACT_VERSION') {
               description('Choose Wisely')
               filterable()
               choiceType('SINGLE_SELECT')
               groovyScript{
                 script('''def mavendata = new XmlSlurper().parse("''' + jobNexusUrl + '''")
          return mavendata.versioning.versions.version*.text()'''
                  )
                  fallbackScript('return ["fallback choice"]')
                }
              }
            }
          }
          Show
          kinow Bruno P. Kinoshita added a comment - The scripts appear to be missing the return statement. I think they should be something like (note return statements, and fallback returns an array): job( 'generated-1' ) { def jobNexusUrl = 'https: //nexus.interna.com/nexus/content/repositories/rdrti2-releases/com/rd/rti/rdrti2/maven-metadata.xml' parameters { activeChoiceParam( 'ARTIFACT_VERSION' ) { description( 'Choose Wisely' ) filterable() choiceType( 'SINGLE_SELECT' ) groovyScript{ script( '''def mavendata = new XmlSlurper().parse( "' '' + jobNexusUrl + ' ''" ) return mavendata.versioning.versions.version*.text()''' ) fallbackScript( ' return [ "fallback choice" ]' ) } } } }
          Hide
          larrycharbonneau Larry Charbonneau added a comment -

          Sorry forgot about this, I dont need this anymore. Work somewhere else now.

          Closing

          Show
          larrycharbonneau Larry Charbonneau added a comment - Sorry forgot about this, I dont need this anymore. Work somewhere else now. Closing
          Hide
          larrycharbonneau Larry Charbonneau added a comment -

          I don't have this problem anymore, i work somewhere else now.

          Show
          larrycharbonneau Larry Charbonneau added a comment - I don't have this problem anymore, i work somewhere else now.

            People

            Assignee:
            kinow Bruno P. Kinoshita
            Reporter:
            larrycharbonneau Larry Charbonneau
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: