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

401 when trying to update the build status in gitea

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: gitea-plugin
    • Labels:
      None
    • Environment:
      Jenkins X with the gitea addon enabled on GKE
    • Similar Issues:

      Description

      I can use Jenkins X with gitea and the gitea-plugin to create repos & setup MultiBranchProjects for PRs/master and webhooks and all that are working great. 
       
      However each pipeilne build fails to update the build status. Here's the exceptions that are generated at the beginning and end of a pipeline run. Its a little odd its a 401 as there's 1 credential used for querying the MBP branches, reading repos from gitea and doing commits/issues/PRs etc - so the credential is fine and the same credential is used in the Jenkins server config + the MBp
       
      Here's a sample stack trace at the start...
      [Gitea] Notifying branch build status: PENDING Build started... ERROR: Could not send notifications org.jenkinsci.plugin.gitea.client.api.GiteaHttpStatusException: HTTP 401/Unauthorized {"context":"test-user/environment-jstrachan-test8-staging/master","description":"Build started...","state":"pending","status":"pending","target_url":"http://jenkins.jx.35.197.207.229.nip.io/job/test-user/job/environment-jstrachan-test8-staging/job/master/2/display/redirect"} at org.jenkinsci.plugin.gitea.client.impl.DefaultGiteaConnection.post(DefaultGiteaConnection.java:911) at org.jenkinsci.plugin.gitea.client.impl.DefaultGiteaConnection.createCommitStatus(DefaultGiteaConnection.java:550) at org.jenkinsci.plugin.gitea.GiteaNotifier.sendNotifications(GiteaNotifier.java:144) at org.jenkinsci.plugin.gitea.GiteaNotifier.access$200(GiteaNotifier.java:66) at org.jenkinsci.plugin.gitea.GiteaNotifier$JobCheckOutListener.onCheckout(GiteaNotifier.java:277) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:127) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:85) at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:75) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47) at hudson.security.ACL.impersonate(ACL.java:290) at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 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)  
       
      then at the end:
      [Gitea] Notifying branch build status: SUCCESS This commit looks good ERROR: Could not send notifications org.jenkinsci.plugin.gitea.client.api.GiteaHttpStatusException: HTTP 401/Unauthorized {"context":"test-user/environment-jstrachan-test8-staging/master","description":"This commit looks good","state":"success","status":"success","target_url":"http://jenkins.jx.35.197.207.229.nip.io/job/test-user/job/environment-jstrachan-test8-staging/job/master/2/display/redirect"} at org.jenkinsci.plugin.gitea.client.impl.DefaultGiteaConnection.post(DefaultGiteaConnection.java:911) at org.jenkinsci.plugin.gitea.client.impl.DefaultGiteaConnection.createCommitStatus(DefaultGiteaConnection.java:550) at org.jenkinsci.plugin.gitea.GiteaNotifier.sendNotifications(GiteaNotifier.java:144) at org.jenkinsci.plugin.gitea.GiteaNotifier.access$200(GiteaNotifier.java:66) at org.jenkinsci.plugin.gitea.GiteaNotifier$JobCompletedListener.onCompleted(GiteaNotifier.java:297) at hudson.model.listeners.RunListener.fireCompleted(RunListener.java:211) at org.jenkinsci.plugins.workflow.job.WorkflowRun.finish(WorkflowRun.java:688) at org.jenkinsci.plugins.workflow.job.WorkflowRun.access$1400(WorkflowRun.java:143) at org.jenkinsci.plugins.workflow.job.WorkflowRun$GraphL.onNewHead(WorkflowRun.java:1006) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.notifyListeners(CpsFlowExecution.java:1368) at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$3.run(CpsThreadGroup.java:412) at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35) at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131) at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) 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) Finished: SUCCESS

        Attachments

        1. actions.png
          actions.png
          27 kB
        2. actions.png
          actions.png
          27 kB
        3. plugin.png
          plugin.png
          11 kB
        4. plugin.png
          plugin.png
          11 kB
        5. Screen Shot 2018-08-03 at 13.27.37.png
          Screen Shot 2018-08-03 at 13.27.37.png
          28 kB
        6. Screen Shot 2018-08-03 at 13.27.48.png
          Screen Shot 2018-08-03 at 13.27.48.png
          28 kB
        7. Screen Shot 2018-08-03 at 13.34.44.png
          Screen Shot 2018-08-03 at 13.34.44.png
          337 kB
        8. Screen Shot 2018-08-03 at 13.35.16.png
          Screen Shot 2018-08-03 at 13.35.16.png
          18 kB
        9. Screen Shot 2018-08-03 at 13.36.15.png
          Screen Shot 2018-08-03 at 13.36.15.png
          28 kB
        10. Screen Shot 2018-08-03 at 13.36.36.png
          Screen Shot 2018-08-03 at 13.36.36.png
          17 kB

          Activity

          Hide
          jstrachan James Strachan added a comment -

          this could maybe be related to the kind of Credential it is and its format/data - we hit a similar issue with Bitbucket on Jenkins X: https://github.com/jenkins-x/jx/issues/665

          Show
          jstrachan James Strachan added a comment - this could maybe be related to the kind of Credential it is and its format/data - we hit a similar issue with Bitbucket on Jenkins X:  https://github.com/jenkins-x/jx/issues/665
          Hide
          jstrachan James Strachan added a comment -

          Turns out it’s not related! Tried using a manually created regular username/password - plus a Gitea Personal Access Token credential- they all fail with a 401

          Show
          jstrachan James Strachan added a comment - Turns out it’s not related! Tried using a manually created regular username/password - plus a Gitea Personal Access Token credential- they all fail with a 401
          Hide
          michaelneale Michael Neale added a comment - - edited

          James Strachan I was able to reproduce it - but by incorrectly using a personal access token as a "password" type of credential.This resulted in 401s. 

          Unlike in github's case, the personal access token for gitea can't just be dropped in place of the password (I think). 

          When I set it up as the correct credential type - it did work for me and set the status correctly. 

           

          https://github.com/jenkinsci/gitea-plugin/blob/master/src/main/java/org/jenkinsci/plugin/gitea/credentials/PersonalAccessToken.java

          https://github.com/jenkinsci/gitea-plugin/blob/master/src/main/java/org/jenkinsci/plugin/gitea/client/impl/DefaultGiteaConnection.java#L826 (see how it uses the token header in the token case, but not username/password)

           

          Anyway - will discuss on this: https://github.com/jenkins-x/jx/issues/432#issuecomment-397531961 as JIRA commenting is annoying me (and can confirm if that was the issue blocking things) - as I don't think this is a bug if it is what I think it is. 

          Show
          michaelneale Michael Neale added a comment - - edited James Strachan  I was able to reproduce it - but by incorrectly using a personal access token as a "password" type of credential.This resulted in 401s.  Unlike in github's case, the personal access token for gitea can't just be dropped in place of the password (I think).  When I set it up as the correct credential type - it did work for me and set the status correctly.    https://github.com/jenkinsci/gitea-plugin/blob/master/src/main/java/org/jenkinsci/plugin/gitea/credentials/PersonalAccessToken.java https://github.com/jenkinsci/gitea-plugin/blob/master/src/main/java/org/jenkinsci/plugin/gitea/client/impl/DefaultGiteaConnection.java#L826  (see how it uses the token header in the token case, but not username/password)   Anyway - will discuss on this: https://github.com/jenkins-x/jx/issues/432#issuecomment-397531961  as JIRA commenting is annoying me (and can confirm if that was the issue blocking things) - as I don't think this is a bug if it is what I think it is. 
          Hide
          stephenconnolly Stephen Connolly added a comment -

          So, does your user have the correct permissions to post status updates?

          Here is Jenkins building when using my api token:

          Here is Jenkins building when using my user/pass:

          Here is Jenkins building when using the user bob who has Read permission only on the repo:


          Now if we give bob Write permissions on the repo:


          So it seems like the issue here is that you are getting an ugly error message... though the message is completely accurate, could not send notification because unauthorized.

          Seems like everything is functioning as designed

          Show
          stephenconnolly Stephen Connolly added a comment - So, does your user have the correct permissions to post status updates? Here is Jenkins building when using my api token: Here is Jenkins building when using my user/pass: Here is Jenkins building when using the user bob who has Read permission only on the repo: Now if we give bob Write permissions on the repo: So it seems like the issue here is that you are getting an ugly error message... though the message is completely accurate, could not send notification because unauthorized. Seems like everything is functioning as designed
          Hide
          stephenconnolly Stephen Connolly added a comment -

          If we want an issue to make the error message prettier, that's fine, but the functionality works and the error message is reporting the exact issue correctly from what I can see

          Show
          stephenconnolly Stephen Connolly added a comment - If we want an issue to make the error message prettier, that's fine, but the functionality works and the error message is reporting the exact issue correctly from what I can see
          Hide
          jstrachan James Strachan added a comment - - edited

          Stephen Connolly I wonder in your tests was that a regular UserPasswordCredential class being used under the covers? I'm wondering if this is an effect of using the kubernetes credentials provider plugin which creates the credentials and is only aware of the standard Credential implementation classes right now

          Show
          jstrachan James Strachan added a comment - - edited Stephen Connolly I wonder in your tests was that a regular UserPasswordCredential class being used under the covers? I'm wondering if this is an effect of using the kubernetes credentials provider plugin which creates the credentials and is only aware of the standard Credential implementation classes right now
          Hide
          naer Fran Aguiar added a comment -

          How can I use this feature?
          I already have installed gitea-plugin, but in my build steps I don't see nothing related to this.

          See captures, there is github, but not gitea... What I'm missing?

           

           

          Any idea?

          Show
          naer Fran Aguiar added a comment - How can I use this feature? I already have installed gitea-plugin, but in my build steps I don't see nothing related to this. See captures, there is github, but not gitea... What I'm missing?     Any idea?

            People

            • Assignee:
              Unassigned
              Reporter:
              jstrachan James Strachan
            • Votes:
              2 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: