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

/var/lib/jenkins/init.groovy.d/create-github-oauth.groovy fails on initialisation

    Details

    • Similar Issues:

      Description

      After upgrading Jenkins to ver. 2.126 the 

      /var/lib/jenkins/init.groovy.d/create-github-oauth.groovy fails with the below error:

       
      Jun 04, 2018 12:07:19 PM WARNING jenkins.util.groovy.GroovyHookScript execute
      Failed to run script file:/var/lib/jenkins/init.groovy.d/create-github-oauth.groovy groovy.lang.GroovyRuntimeException: Could not find matching constructor for: org.jenkinsci.plugins.GithubSecurityRealm(java.lang.String, java.lang.String, java.lang.String, java.lang.String) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1732) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1532) at org.codehaus.groovy.runtime.callsite.MetaClassConstructorSite.callConstructor(MetaClassConstructorSite.java:49) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:271) at create-github-oauth.run(create-github-oauth.groovy:6) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585) at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:136) at jenkins.util.groovy.GroovyHookScript.execute(GroovyHookScript.java:127) at jenkins.util.groovy.GroovyHookScript.run(GroovyHookScript.java:110) at hudson.init.impl.GroovyInitScript.init(GroovyInitScript.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104) at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175) at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296) at jenkins.model.Jenkins$5.runTask(Jenkins.java:1068) at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214) at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

       

      also the multibranch pipeline jobs using Jenkins scripted pipeline stopped working:

       

      They fail at start with:

       

      Started by user *****************
      java.io.FileNotFoundException: https://api.github.com/
      at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
      at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
      at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
      at org.kohsuke.github.Requester.parse(Requester.java:612)
      at org.kohsuke.github.Requester.parse(Requester.java:594)
      at org.kohsuke.github.Requester._to(Requester.java:272)
      Caused: org.kohsuke.github.GHFileNotFoundException: {"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}
      at org.kohsuke.github.Requester.handleApiError(Requester.java:686)
      at org.kohsuke.github.Requester._to(Requester.java:293)
      at org.kohsuke.github.Requester.to(Requester.java:234)
      at org.kohsuke.github.GitHub.checkApiUrlValidity(GitHub.java:703)
      at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.checkApiUrlValidity(GitHubSCMSource.java:1351)
      at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource.retrieve(GitHubSCMSource.java:1404)
      at jenkins.scm.api.SCMSource.fetch(SCMSource.java:566)
      at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:95)
      at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:298)
      at hudson.model.ResourceController.execute(ResourceController.java:97)
      at hudson.model.Executor.run(Executor.java:429)
      Finished: FAILURE

       

      NOTE: Please note that the GitHub creds have not changed and they work just fine in other manually created jobs.

       

        Attachments

          Activity

          Hide
          oleg_nenashev Oleg Nenashev added a comment -

          Github OAuth constructor changed in a binary-incompatible way hence Groovy Hooks fail.
          The thing is that these changes were at least 3 years ago according to https://github.com/jenkinsci/github-oauth-plugin/blame/master/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java

          I will leave it to Sam Gleske for review

          Show
          oleg_nenashev Oleg Nenashev added a comment - Github OAuth constructor changed in a binary-incompatible way hence Groovy Hooks fail. The thing is that these changes were at least 3 years ago according to https://github.com/jenkinsci/github-oauth-plugin/blame/master/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java I will leave it to Sam Gleske for review
          Hide
          cb_tes_global Constantin Bugneac added a comment - - edited

          Another interesting finding is that Organisation Scan using credentials (username & password) with GitHub doesn't work anymore. I'm getting this in scan log:

          [Mon Jun 04 14:27:42 UTC 2018] Starting organization scan...
          [Mon Jun 04 14:27:42 UTC 2018] Updating actions...
          Looking up details of Tes...
          ERROR: [Mon Jun 04 14:27:42 UTC 2018] Could not refresh actions for navigator org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator@f0ba3f2
          java.io.FileNotFoundException: https://api.github.com/users/Tes
          at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243)
          at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
          at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25)
          at org.kohsuke.github.Requester.parse(Requester.java:612)
          at org.kohsuke.github.Requester.parse(Requester.java:594)
          at org.kohsuke.github.Requester._to(Requester.java:272)
          Caused: org.kohsuke.github.GHFileNotFoundException: {"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}
          at org.kohsuke.github.Requester.handleApiError(Requester.java:686)
          at org.kohsuke.github.Requester._to(Requester.java:293)
          at org.kohsuke.github.Requester.to(Requester.java:234)
          at org.kohsuke.github.GitHub.getUser(GitHub.java:398)
          at org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator.retrieveActions(GitHubSCMNavigator.java:1163)
          at jenkins.scm.api.SCMNavigator.fetchActions(SCMNavigator.java:315)
          at jenkins.branch.OrganizationFolder.computeChildren(OrganizationFolder.java:409)
          at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:276)
          at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165)
          at jenkins.branch.OrganizationFolder$OrganizationScan.run(OrganizationFolder.java:910)
          at hudson.model.ResourceController.execute(ResourceController.java:97)
          at hudson.model.Executor.run(Executor.java:429)
          [Mon Jun 04 14:27:42 UTC 2018] Consulting GitHub Organization
          ERROR: [Mon Jun 04 14:27:43 UTC 2018] Could not fetch sources from navigator org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator@f0ba3f2
          hudson.AbortException: Invalid scan credentials github-user/****** (github-user Github token with correct ID) to connect to https://api.github.com, skipping
          at org.jenkinsci.plugins.github_branch_source.Connector.checkConnectionValidity(Connector.java:435)
          at org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator.visitSources(GitHubSCMNavigator.java:900)
          at jenkins.branch.OrganizationFolder.computeChildren(OrganizationFolder.java:458)
          at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:276)
          at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165)
          at jenkins.branch.OrganizationFolder$OrganizationScan.run(OrganizationFolder.java:910)
          at hudson.model.ResourceController.execute(ResourceController.java:97)
          at hudson.model.Executor.run(Executor.java:429)
          [Mon Jun 04 14:27:43 UTC 2018] Finished organization scan. Scan took 0.52 sec
          FATAL: Invalid scan credentials github-user/****** (github-user Github token with correct ID) to connect to https://api.github.com, skipping
          Finished: FAILURE

           

          despite a simple Jenkins job can checkout the code without any problems using the same credentials (username/password).

           

          Show
          cb_tes_global Constantin Bugneac added a comment - - edited Another interesting finding is that Organisation Scan using credentials (username & password) with GitHub doesn't work anymore. I'm getting this in scan log: [Mon Jun 04 14:27:42 UTC 2018] Starting organization scan... [Mon Jun 04 14:27:42 UTC 2018] Updating actions... Looking up details of Tes... ERROR: [Mon Jun 04 14:27:42 UTC 2018] Could not refresh actions for navigator org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator@f0ba3f2 java.io.FileNotFoundException: https://api.github.com/users/Tes at com.squareup.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:243) at com.squareup.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210) at com.squareup.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:25) at org.kohsuke.github.Requester.parse(Requester.java:612) at org.kohsuke.github.Requester.parse(Requester.java:594) at org.kohsuke.github.Requester._to(Requester.java:272) Caused: org.kohsuke.github.GHFileNotFoundException: {"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"} at org.kohsuke.github.Requester.handleApiError(Requester.java:686) at org.kohsuke.github.Requester._to(Requester.java:293) at org.kohsuke.github.Requester.to(Requester.java:234) at org.kohsuke.github.GitHub.getUser(GitHub.java:398) at org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator.retrieveActions(GitHubSCMNavigator.java:1163) at jenkins.scm.api.SCMNavigator.fetchActions(SCMNavigator.java:315) at jenkins.branch.OrganizationFolder.computeChildren(OrganizationFolder.java:409) at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:276) at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165) at jenkins.branch.OrganizationFolder$OrganizationScan.run(OrganizationFolder.java:910) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) [Mon Jun 04 14:27:42 UTC 2018] Consulting GitHub Organization ERROR: [Mon Jun 04 14:27:43 UTC 2018] Could not fetch sources from navigator org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator@f0ba3f2 hudson.AbortException: Invalid scan credentials github-user/****** (github-user Github token with correct ID) to connect to https://api.github.com , skipping at org.jenkinsci.plugins.github_branch_source.Connector.checkConnectionValidity(Connector.java:435) at org.jenkinsci.plugins.github_branch_source.GitHubSCMNavigator.visitSources(GitHubSCMNavigator.java:900) at jenkins.branch.OrganizationFolder.computeChildren(OrganizationFolder.java:458) at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:276) at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165) at jenkins.branch.OrganizationFolder$OrganizationScan.run(OrganizationFolder.java:910) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) [Mon Jun 04 14:27:43 UTC 2018] Finished organization scan. Scan took 0.52 sec FATAL: Invalid scan credentials github-user/****** (github-user Github token with correct ID) to connect to https://api.github.com , skipping Finished: FAILURE   despite a simple Jenkins job can checkout the code without any problems using the same credentials (username/password).  
          Hide
          sag47 Sam Gleske added a comment -

          Without seeing the source code of your Groovy script I'm not sure I can help.

          Show
          sag47 Sam Gleske added a comment - Without seeing the source code of your Groovy script I'm not sure I can help.
          Hide
          cb_tes_global Constantin Bugneac added a comment -

          Sam Gleske here is the dump of the script:

           

          #!groovy
          import jenkins.model.*
          import hudson.security.*
          import org.jenkinsci.plugins.*
          jenkins = jenkins.model.Jenkins.getInstance()
          githubRealm = new GithubSecurityRealm(
          'https://github.com',
          'https://api.github.com',
          '********************',
          '******************************************'
          )
          jenkins.setSecurityRealm(githubRealm)
          strategy = new FullControlOnceLoggedInAuthorizationStrategy()
          jenkins.setAuthorizationStrategy(strategy)
          jenkins.save()

          Show
          cb_tes_global Constantin Bugneac added a comment - Sam Gleske here is the dump of the script:   #!groovy import jenkins.model.* import hudson.security.* import org.jenkinsci.plugins.* jenkins = jenkins.model.Jenkins.getInstance() githubRealm = new GithubSecurityRealm( 'https://github.com', 'https://api.github.com', '********************', '******************************************' ) jenkins.setSecurityRealm(githubRealm) strategy = new FullControlOnceLoggedInAuthorizationStrategy() jenkins.setAuthorizationStrategy(strategy) jenkins.save()
          Hide
          sag47 Sam Gleske added a comment -

          Constantin Bugneac looking at the latest released version of the plugin at the time of this writing github-oauth 0.29 https://github.com/jenkinsci/github-oauth-plugin/blob/github-oauth-0.29/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java#L127-L132

          Here's your new script:

          #!groovy
          import jenkins.model.*
          import hudson.security.*
          import org.jenkinsci.plugins.*
          jenkins = jenkins.model.Jenkins.getInstance()
          githubRealm = new GithubSecurityRealm(
          'https://github.com',
          'https://api.github.com',
          '********************',
          '******************************************',
          'read:org,user:email'
          )
          jenkins.setSecurityRealm(githubRealm)
          strategy = new FullControlOnceLoggedInAuthorizationStrategy()
          jenkins.setAuthorizationStrategy(strategy)
          jenkins.save()
          

          If you're working with private repositories, then you'll need to add `repo` OAuth scope. So: 'read:org,user:email,repo'

          Show
          sag47 Sam Gleske added a comment - Constantin Bugneac looking at the latest released version of the plugin at the time of this writing github-oauth 0.29 https://github.com/jenkinsci/github-oauth-plugin/blob/github-oauth-0.29/src/main/java/org/jenkinsci/plugins/GithubSecurityRealm.java#L127-L132 Here's your new script: #!groovy import jenkins.model.* import hudson.security.* import org.jenkinsci.plugins.* jenkins = jenkins.model.Jenkins.getInstance() githubRealm = new GithubSecurityRealm( 'https://github.com', 'https://api.github.com', '********************', '******************************************', 'read:org,user:email' ) jenkins.setSecurityRealm(githubRealm) strategy = new FullControlOnceLoggedInAuthorizationStrategy() jenkins.setAuthorizationStrategy(strategy) jenkins.save() If you're working with private repositories, then you'll need to add `repo` OAuth scope. So: 'read:org,user:email,repo'
          Hide
          sag47 Sam Gleske added a comment -

          Closing as not a defect because it was a bug in Constantin Bugneac script and not the github-oauth-plugin.

          Show
          sag47 Sam Gleske added a comment - Closing as not a defect because it was a bug in Constantin Bugneac script and not the github-oauth-plugin.
          Hide
          cb_tes_global Constantin Bugneac added a comment -

          Thanks Sam Gleske. Now the script is executing OK.

          Show
          cb_tes_global Constantin Bugneac added a comment - Thanks Sam Gleske . Now the script is executing OK.

            People

            • Assignee:
              sag47 Sam Gleske
              Reporter:
              cb_tes_global Constantin Bugneac
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: