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

atlassian bitbucket plugin is broken with SSH only credentials for multibranch jobs.

XMLWordPrintable

      I've created a multibranch project with Bitbucket Server as a branch source.

      Here is the Branch Source configuration

      Connection test is successful.

      When I save the job, I see this exception in the branch scan

      Started
      [Sat Feb 13 18:03:26 UTC 2021] Starting branch indexing...
      ERROR: [Sat Feb 13 18:03:26 UTC 2021] Could not fetch branches from source d16c26c9-5fba-4a68-b49c-6d1f74536011
      java.lang.NullPointerException
      	at hudson.Util.getDigestOf(Util.java:636)
      	at jenkins.plugins.git.AbstractGitSCMSource.getCacheEntry(AbstractGitSCMSource.java:1391)
      	at jenkins.plugins.git.AbstractGitSCMSource.getCacheEntry(AbstractGitSCMSource.java:1218)
      	at jenkins.plugins.git.AbstractGitSCMSource.doRetrieve(AbstractGitSCMSource.java:339)
      	at jenkins.plugins.git.AbstractGitSCMSource.retrieve(AbstractGitSCMSource.java:566)
      	at com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMSource$CustomGitSCMSource.accessibleRetrieve(BitbucketSCMSource.java:504)
      	at com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMSource.retrieve(BitbucketSCMSource.java:232)
      	at jenkins.scm.api.SCMSource._retrieve(SCMSource.java:373)
      	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:283)
      	at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:641)
      	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:278)
      	at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165)
      	at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1032)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:429)
      [Sat Feb 13 18:03:26 UTC 2021] Finished branch indexing. Indexing took 3 ms
      FATAL: Failed to recompute children of foo
      java.lang.NullPointerException
      	at hudson.Util.getDigestOf(Util.java:636)
      	at jenkins.plugins.git.AbstractGitSCMSource.getCacheEntry(AbstractGitSCMSource.java:1391)
      	at jenkins.plugins.git.AbstractGitSCMSource.getCacheEntry(AbstractGitSCMSource.java:1218)
      	at jenkins.plugins.git.AbstractGitSCMSource.doRetrieve(AbstractGitSCMSource.java:339)
      	at jenkins.plugins.git.AbstractGitSCMSource.retrieve(AbstractGitSCMSource.java:566)
      	at com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMSource$CustomGitSCMSource.accessibleRetrieve(BitbucketSCMSource.java:504)
      	at com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMSource.retrieve(BitbucketSCMSource.java:232)
      	at jenkins.scm.api.SCMSource._retrieve(SCMSource.java:373)
      	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:283)
      	at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:641)
      	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:278)
      	at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:165)
      	at jenkins.branch.MultiBranchProject$BranchIndexing.run(MultiBranchProject.java:1032)
      	at hudson.model.ResourceController.execute(ResourceController.java:97)
      	at hudson.model.Executor.run(Executor.java:429)
      Finished: FAILURE
      

      Looking at config.xml

        <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api@2.6.2">
          <data>
            <jenkins.branch.BranchSource>
              <source class="com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMSource" plugin="atlassian-bitbucket-server-integration@2.1.2">
                <traits>
                  <jenkins.plugins.git.traits.BranchDiscoveryTrait plugin="git@4.5.2"/>
                </traits>
                <gitSCMSource>
                  <credentialsId>git-ssh-creds</credentialsId>
                  <traits>
                    <jenkins.plugins.git.traits.BranchDiscoveryTrait reference="../../../traits/jenkins.plugins.git.traits.BranchDiscoveryTrait"/>
                  </traits>
                </gitSCMSource>
                <repository>
                  <credentialsId></credentialsId>
                  <sshCredentialsId>git-ssh-creds</sshCredentialsId>
                  <projectKey>devops</projectKey>
                  <projectName>devops</projectName>
                  <repositoryName>cre-jenkins</repositoryName>
                  <repositorySlug>cre-jenkins</repositorySlug>
                  <serverId>bitbucket-server</serverId>
                  <mirrorName></mirrorName>
                </repository>
                <webhookRegistered>false</webhookRegistered>
              </source>
              <strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
                <properties class="empty-list"/>
              </strategy>
            </jenkins.branch.BranchSource>
          </data>
          <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
        </sources>
      

      If you look at the `gitSCMSource` element you will see that the `<remote>` element is missing.

      Creating the same job through the Job DSL plugin and fixing missing `<remote>` element makes job execution successful.

      Bellow is a snippet of the Job DSL script with the fixup (configure block at the end) to make this configuration workable.

      multibranchPipelineJob( pipeline ) {
      
        displayName( pipeline )
        branchSources {
          branchSource {
            source {
              BbS {
                id( ATLASSIAN_BITBUCKET_SERVER_ID )
                serverId( ATLASSIAN_BITBUCKET_SERVER_ID )
                credentialsId( '' )
                mirrorName( '' )
                projectName( project )
                repositoryName( repo )
                sshCredentialsId( SSH_CREDENTIALS_ID )
      
                traits {
                  gitBranchDiscovery()
                }
              }
            }
          }
        }
      
        factory {
          workflowBranchProjectFactory {
            scriptPath( jenkins_file )
          }
        }
        orphanedItemStrategy {
          discardOldItems {
            daysToKeep(30)
            numToKeep(20)
          }
        }
        triggers {
          BitbucketWebhookMultibranchTriggerImpl()
        }
      
        // Little fixup for missing remote on gitSCMSource
        configure { rootNode ->
          rootNode /
            sources /
              data /
                'jenkins.branch.BranchSource' /
                  source /
                    gitSCMSource /
                      remote << ssh_url
        }
      }
      

      Even though I can create my jobs through Job DSL, I cannot edit them after the fact, because making any changes to the job (i.e. changing project/repo name to a different value due to repo move) results in SSH url being removed from the `gitSCMSource`

            Unassigned Unassigned
            alex_pogrebnyak_sophos Alex Pogrebnyak
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: