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

Script runs in Script Console but not with Job DSL groovy

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Issue Links

            Activity

            sag47 Sam Gleske created issue -
            daspilker Daniel Spilker made changes -
            Field Original Value New Value
            Link This issue duplicates JENKINS-27517 [ JENKINS-27517 ]
            daspilker Daniel Spilker made changes -
            Resolution Duplicate [ 3 ]
            Status Open [ 1 ] Resolved [ 5 ]
            daspilker Daniel Spilker made changes -
            Status Resolved [ 5 ] Closed [ 6 ]
            rtyler R. Tyler Croy made changes -
            Workflow JNJira [ 163555 ] JNJira + In-Review [ 208840 ]

              People

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

                Dates

                Created:
                Updated:
                Resolved: