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

Script runs in Script Console but not with Job DSL groovy

XMLWordPrintable

      The following script runs fine in the Script Console but not in a Job DSL script.

      import jenkins.*
      import jenkins.model.*
      import hudson.*
      import hudson.model.*
      
      def credentials = Jenkins.instance.getExtensionList(com.cloudbees.jenkins.GitHubPushTrigger.DescriptorImpl.class)[0].getCredentials()
      
      if(credentials.size() > 0) {
        credentials.each {
          if(it.apiUrl.length() > 0) {
            println("apiUrl: " + it.apiUrl)
          }
          else {
            println("apiUrl: https://api.github.com/")
          }
          println("username: " + it.username)
          println("oauthAccessToken: " + it.oauthAccessToken)
        }
      }
      

      I recall that the Job DSL plugin executes groovy scripts in the Jenkins runtime. I'm getting info out of the configured github plugin (specifically the automatically manage hooks section).

      Can you see anything that I'm obviously doing wrong? Also, there's this text from the script console: "All the classes from all the plugins are visible." The same does not appear to apply in Job DSL scripts.

      Any advice is appreciated.

            daspilker Daniel Spilker
            sag47 Sam Gleske
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: