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

PR can't checkout with bitbucket access token

XMLWordPrintable

      According this description it is possible to checkout a Bitbucket repository with an access token:

       

      [Using Repository Access Tokens | Bitbucket Cloud | Atlassian Support|https://support.atlassian.com/bitbucket-cloud/docs/using-access-tokens/]

       

      We have generated an access token and added it as an secret text to the jenkins credentials.

      it is possible list all repos in your plugin.

      builds gets triggered by pull requests and branch events.

       

      by generating a access token in Bitbucket also generates a pseudo username

      somehow this username is part of the git url during the PR checkout and the authentification fails

       

      we run our builds on a jenkins slave. i had similiar problems on the slave when i used

      "scm checkout" 

      i had to change this command to:

                              def scmUrl = scm.getUserRemoteConfigs()[0].getUrl()
                              
                              URL scmUri = new URL(scmUrl)
                              
                              def protocol = scmUri?.getProtocol()
                              def host = scmUri?.getHost()
                              def path = scmUri?.getPath()
                              
                              def newUrl = "${protocol}://${host}${path}"
                              
                              checkout([
                                  $class: 'GitSCM',
                                  branches: scm.branches,
                                  doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
                                  extensions: scm.extensions,
                                  userRemoteConfigs: [
                                      [url: newUrl, credentialsId: 'x-token-auth']
                                  ]
                              ])

      to overwrite the username and refer to the authentification token.

      that worked fine, but the problem with the PR happens much earlier in the build and i can't find a solution.

      i hope you can find a solution.

      Thank you

      Özdem

            Unassigned Unassigned
            hepero Özdem
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: