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

Disabling HTTPS cloning protocol on Data Center causes builds to fail even if SSH checkout feature is configured

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    • Jenkins 2.492.3
      Bitbucket Branch Source 936.1.0
    • 936.1.1

      Since version 936.0 the SSH checkout trait is broken (at least when scanning an organizational folder). My source is Bitbucket Data Center, the API credentials is an HTTP Access Token and cloning is done using an SSH private key.

      When I create an organizational folder I get the following error:

      ERROR: [Mon Apr 28 20:54:28 CEST 2025] Could not fetch branches from source com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMNavigator::https://***
      [Mon Apr 28 20:54:28 CEST 2025] Finished branch indexing. Indexing took 1.2 sec
      FATAL: Failed to recompute children of XYZ
      java.lang.IllegalStateException: Can't find clone link for protocol HTTP
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder.lambda$getCloneLink$1(BitbucketGitSCMBuilder.java:324)
          at java.base/java.util.Optional.orElseThrow(Unknown Source)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder.getCloneLink(BitbucketGitSCMBuilder.java:324)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder.withPrimaryRemote(BitbucketGitSCMBuilder.java:311)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder.withBranchRemote(BitbucketGitSCMBuilder.java:304)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder.withBitbucketRemote(BitbucketGitSCMBuilder.java:207)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketGitSCMBuilder.withCloneLinks(BitbucketGitSCMBuilder.java:139)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.build(BitbucketSCMSource.java:726)
          at PluginClassLoader for scm-api//jenkins.scm.api.SCMSource.build(SCMSource.java:934)
          at PluginClassLoader for branch-api//jenkins.branch.MultiBranchProject.newBranch(MultiBranchProject.java:563)
          at PluginClassLoader for branch-api//jenkins.branch.MultiBranchProject$SCMHeadObserverImpl.observe(MultiBranchProject.java:2016)
          at PluginClassLoader for scm-api//jenkins.scm.api.trait.SCMSourceRequest.process(SCMSourceRequest.java:357)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSourceRequest.process(BitbucketSCMSourceRequest.java:614)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.retrieveBranches(BitbucketSCMSource.java:521)
          at PluginClassLoader for cloudbees-bitbucket-branch-source//com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource.retrieve(BitbucketSCMSource.java:366)
          at PluginClassLoader for scm-api//jenkins.scm.api.SCMSource._retrieve(SCMSource.java:372)
          at PluginClassLoader for scm-api//jenkins.scm.api.SCMSource.fetch(SCMSource.java:282)
          at PluginClassLoader for branch-api//jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:661)
          at PluginClassLoader for cloudbees-folder//com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:272)
          at PluginClassLoader for cloudbees-folder//com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:171)
          at PluginClassLoader for branch-api//jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1064)
          at hudson.model.ResourceController.execute(ResourceController.java:101)
          at hudson.model.Executor.run(Executor.java:446)
      Finished: FAILURE

       

      After some debugging it appears that #1024 is the culprit. In BitbucketSCMSource.build() it passes my API credentials to 
      new BitbucketGitSCMBuilder(). Then BitbucketGitSCMBuilder.withCredentials() initializes the builder with protocol HTTP instead of SSH.
       
      If I build the plugin from source after applying the below patch, everything works again in my local environment (but I don't know if this is a proper fix):

      diff --git a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java
      index d0d8148..f0b5a51 100644
      --- a/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java
      +++ b/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java
      @@ -721,7 +721,8 @@ public class BitbucketSCMSource extends SCMSource {
           public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) {
               initCloneLinks();
      
      -        BitbucketGitSCMBuilder scmBuilder = new BitbucketGitSCMBuilder(this, head, revision, credentialsId)
      +        SSHCheckoutTrait sshCheckoutTrait = SCMTrait.find(traits, SSHCheckoutTrait.class);
      +        BitbucketGitSCMBuilder scmBuilder = new BitbucketGitSCMBuilder(this, head, revision, sshCheckoutTrait != null ? sshCheckoutTrait.getCredentialsId() : credentialsId)
                       .withExtension(new BitbucketEnvVarExtension(getRepoOwner(), getRepository(), getProjectKey(), getServerUrl()))
                       .withCloneLinks(primaryCloneLinks, mirrorCloneLinks)
                       .withTraits(traits);
      

            nfalco Nikolas Falco
            sunmar Marijn van Zon
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: