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

Provide logging for BitbucketClientException when attempting to fetch mirror from non-DC instance

      When attempting to fetch a non-null mirror name against a Bitbucket Server license, the upstream will return an error which is sent back unhelpfully as an unhandled BitbucketClientException with no logging (except the error code). This should be caught when initializing an SCM or SCMSource to ask users to check the status of their mirror or license.

      Original description:

      Hi, 

      I am trying to see a pipeline job, executing the DSL script below.

      When the serverId is left blank, it works, but then we have to manually open the generated pipeline job to select the server, which is not an automated way.

      When the serverId is filled with the id related to the Bitbucket server defined in jenkins configuration , the generation fails, with the following error:

      java.lang.IllegalArgumentException: Could not instantiate {id=74aeb686-0b0d-41a8-b1de-b635e74ca659, branches=[feature/DEVOPS-122-creates-a-dsl-job-to-automate-bitbucket-pipeline-j], credentialsId=git-token, mirrorName=Primary Server, projectName=software, repositoryName=devops-fwk, serverId=ce23d98c-d9b6-43cc-ab84-6f205c3fb812, sshCredentialsId=null, gitTool=null, extensions=[]} for com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCM: java.lang.reflect.InvocationTargetException

      ...

      ..

      .

      Caused by: com.atlassian.bitbucket.jenkins.internal.client.exception.BadRequestException: - response: 409

       

      -----------

      My assumption is that there is an internal failured related to the temptative to create a webhook which fails in a automated way.

      Any workaround or fix to propose?

      Generating this file from a DSL is key, since jenkins master creation is fully automated, no means to use jenkins front end to manually fine tune some jobs

       

       

      #Unable to render embedded object: File (/usr/bin/env groovy#) not found./usr/bin/env groovy

      pipelineJob("BitbucketExample") {   

      triggers

      {      BitbucketWebhookTriggerImpl\{         pullRequestTrigger(false)         refTrigger(true)       }

          }     

      definition {       

      cpsScm {                       

      scm {                   

      BbS {                     

      id("id")                     

      branches {                       

      branchSpec

      {                          name("branchname")                        }

                           

      }                     

      credentialsId("token")                     

      mirrorName("Primary Server")                     

      projectName("proj")                     

      repositoryName("repo")                     

      serverId('XXXXX')

      sshCredentialsId(null)                     

      gitTool(null)                   

      }           

      lightweight()                     

      scriptPath("Jenkinsfile")       

      }    }}

          [JENKINS-67593] Provide logging for BitbucketClientException when attempting to fetch mirror from non-DC instance

          Checking Bitbucket server log, we finally found the root cause: Mirror shall be set to empty . Tested successfully 

          17.0.1 "GET /rest/mirroring/1.0/repos/320/mirrors HTTP/1.1" c.a.s.i.r.e.ServiceExceptionMapper Mapping ServiceException to REST response 409

          com.atlassian.bitbucket.mirroring.upstream.MirroringDisabledException: Mirroring requires a Bitbucket Data Center license.

          => This ticket should be closed, algthough  getting details related to response 409 from Jenkins UI could be VERY helpful to ease settings

          Cedric Bernard added a comment - Checking Bitbucket server log, we finally found the root cause: Mirror shall be set to empty . Tested successfully  17.0.1 "GET /rest/mirroring/1.0/repos/320/mirrors HTTP/1.1" c.a.s.i.r.e.ServiceExceptionMapper Mapping ServiceException to REST response 409 com.atlassian.bitbucket.mirroring.upstream.MirroringDisabledException: Mirroring requires a Bitbucket Data Center license. => This ticket should be closed, algthough  getting details related to response 409 from Jenkins UI could be VERY helpful to ease settings

          Martin Henschke added a comment - - edited

          Hi Cedric, thanks for the report and the comment, and apologies for the rather wordy response.

          First thing I need to say is our plugin technically does not yet have testing, and ergo support for DSL, which I'm telling you to indicate that the support I can provide is limited. Support for Job DSL is tracked in JENKINS-64801.

          That said, I think the error here is a confusion between the mirrorName and mirror value. In our configuration we always provide the "Primary Server" as a default value when selecting a mirror- but Primary Server is just a label, not the mirror name- that value is provided by the mirrors, and an empty string or null value is used instead to indicate no mirror, i.e. use the upstream URL instead. Your DSL I believe is telling Jenkins to query Bitbucket for a mirror named Primary Server, and because you're not in a DC license, the request fails, and the SCM fails to initialize.

          I believe this can be solved by changing your script to omit the mirrorName altogether, or change it to `mirrorName("")`.

          I agree that better handling of the BitbucketClientException you're getting from the upstream is called for here. I'll leave this ticket open for now, but will make some changes to the description/title to clarify, and lower the severity to trivial.

          Let me know if you have any further issues.

          Martin Henschke added a comment - - edited Hi Cedric, thanks for the report and the comment, and apologies for the rather wordy response. First thing I need to say is our plugin technically does not yet have testing, and ergo support for DSL, which I'm telling you to indicate that the support I can provide is limited. Support for Job DSL is tracked in JENKINS-64801 . That said, I think the error here is a confusion between the mirrorName and mirror value. In our configuration we always provide the "Primary Server" as a default value when selecting a mirror- but Primary Server is just a label, not the mirror name- that value is provided by the mirrors, and an empty string or null value is used instead to indicate no mirror, i.e. use the upstream URL instead. Your DSL I believe is telling Jenkins to query Bitbucket for a mirror named Primary Server, and because you're not in a DC license, the request fails, and the SCM fails to initialize. I believe this can be solved by changing your script to omit the mirrorName altogether, or change it to `mirrorName("")`. I agree that better handling of the BitbucketClientException you're getting from the upstream is called for here. I'll leave this ticket open for now, but will make some changes to the description/title to clarify, and lower the severity to trivial. Let me know if you have any further issues.

          Hi, thanks for your feedback.

          I confirm, this is the workaround I have used to fill mirrorName with an empty value, which works fine. You can leave this ticket open for exception handling improvement, since it might be helpful for others

           

          Cedric Bernard added a comment - Hi, thanks for your feedback. I confirm, this is the workaround I have used to fill mirrorName with an empty value, which works fine. You can leave this ticket open for exception handling improvement, since it might be helpful for others  

            Unassigned Unassigned
            cbernard_psee Cedric Bernard
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: