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

Sidebar link "View Branch" URL-encodes slashes in branch name too much

    • 3.2.1

      I have a multibranch project using the Bitbucket Server Integration plugin. One of the branches is named "bugfix/docfx-improve-this-doc".

      On the Jenkins controller, the web page "https://jenkins-REDACTED/jenkins/job/REDACTED/job/REDACTED/job/bugfix%252Fdocfx-improve-this-doc/" displays:

      Pipeline bugfix/docfx-improve-this-doc
      Full project name: REDACTED/REDACTED/bugfix%2Fdocfx-improve-this-doc

      i.e. the Git branch name "bugfix/docfx-improve-this-doc" is encoded as "bugfix%2Fdocfx-improve-this-doc" in the Jenkins job name, and this is further encoded as "bugfix%252Fdocfx-improve-this-doc" in the Jenkins project URL. A bit verbose but OK so far.

      The sidebar of this Jenkins web page also has a link "View Branch" pointing to "https://bitbucket.REDACTED/projects/REDACTED/repos/REDACTED/compare/commits?sourceBranch=refs%2Fheads%2Fbugfix%252Fdocfx-improve-this-doc". This is wrong and leads to a Bitbucket Server page saying "'bugfix%2Fdocfx-improve-this-doc' may have been deleted or renamed. Please choose a new source." The link should instead be "https://bitbucket.REDACTED/projects/REDACTED/repos/REDACTED/compare/commits?sourceBranch=refs%2Fheads%2Fbugfix%2Fdocfx-improve-this-doc", i.e. using just %2F rather than %252F.

      The bug seems to be that BitbucketJobLinkActionFactory.createFor(Job target) calls externalLinkUtils.createBranchDiffLink(scmRepository, target.getName()), where target.getName() returns the Jenkins job name "bugfix%2Fdocfx-improve-this-doc" rather than the Git branch name "bugfix/docfx-improve-this-doc".

      I think this should instead call SCMHead.HeadByItem.findHead​(Item item) to get an SCMHead, and then call SCMHead.getName() to get the branch name. That way, it would not assume any relation between Git branch names and Jenkins job names.

      (After the 3.1.0 release, BitbucketJobLinkActionFactory has been edited to fix JENKINS-67199, but the target.getName() call is still there.)

          [JENKINS-67482] Sidebar link "View Branch" URL-encodes slashes in branch name too much

          Besides, SCMHead.HeadByItem.findHead​(Item item) and SCMSource.SourceByItem.findSource​(Item item) would work better on multibranch projects that have multiple SCM sources pointing to separate repositories on Bitbucket Server. The current BitbucketJobLinkActionFactory.createFor implementation just finds the first BitbucketSCMSource of the multibranch project even if the branch came from another BitbucketSCMSource or from a different type of SCMSource.

          Kalle Niemitalo added a comment - Besides, SCMHead.HeadByItem.findHead​(Item item) and SCMSource.SourceByItem.findSource​(Item item) would work better on multibranch projects that have multiple SCM sources pointing to separate repositories on Bitbucket Server. The current BitbucketJobLinkActionFactory.createFor implementation just finds the first BitbucketSCMSource of the multibranch project even if the branch came from another BitbucketSCMSource or from a different type of SCMSource.

            mhenschke_atlassian Martin Henschke
            kon Kalle Niemitalo
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: