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

Automatically add "Bitbucket" hyperlink to sidebar

    XMLWordPrintable

Details

    • 3.0.0

    Description

      In a Multibranch Pipeline project using Bitbucket Branch Source Plugin, a "Bitbucket" hyperlink is automatically added to the Jenkins sidebar:

      • In the multibranch project itself, the link points to the front page of the repository in Bitbucket Server:
        http://{host}:7990/projects/{project}/repos/{repo}
      • In each branch, the link points to the Bitbucket Server page that compares that branch with the default branch:
        http://{host}:7990/projects/{project}/repos/{repo}/compare/commits?sourceBranch={ref}
      • In each pull request, there is a link.

      I would like Bitbucket Server Integration to add similar hyperlinks. Except perhaps the per-branch link could point to the commit list of the branch instead, as that would have something to display for the default branch:
      http://{host}:7990/projects/{project}/repos/{repo}/commits?until={ref}

      Attachments

        Issue Links

          Activity

            kon Kalle Niemitalo added a comment - I added a few comments to https://github.com/jenkinsci/atlassian-bitbucket-server-integration-plugin/pull/192 .
            sam117 Viktor Sam added a comment - - edited

            Hi! there is some issues with giflow like branch naming in multibranch pipeline
            In build link View Branch:

            branch name:

            feature/DEVOPS-128

            url tail:
            /commits?sourceBranch=refs%2Fheads%2Ffeature*%252F*DEVOPS-128
            %252 - is double slash, so BB  can't find source branch to compare

            sam117 Viktor Sam added a comment - - edited Hi! there is some issues with giflow like branch naming in multibranch pipeline In build link  View Branch: branch name: feature/DEVOPS-128 url tail: /commits?sourceBranch=refs%2Fheads%2Ffeature*%252F*DEVOPS-128 %252 - is double slash, so BB  can't find source branch to compare

            sam117, the bug seems to be that the externalLinkUtils.createBranchDiffLink(scmRepository, target.getName()) calls in BitbucketJobLinkActionFactory use the job name rather than the branch name. That code was last changed in 2021-05-17 for this JENKINS-63070.

            For the "Multibranch Pipeline Job built with the SCM Source" case, I think this could use SCMHead.HeadByItem.findHead(Item item) and then SCMHead.getName(). Perhaps there is an alternative approach via branch-api-plugin, as well.

            For the "Multibranch Pipeline Job built with an SCMStep" case, I am not sure how this should be done.

            kon Kalle Niemitalo added a comment - sam117 , the bug seems to be that the externalLinkUtils.createBranchDiffLink(scmRepository, target.getName()) calls in BitbucketJobLinkActionFactory use the job name rather than the branch name. That code was last changed in 2021-05-17 for this JENKINS-63070 . For the "Multibranch Pipeline Job built with the SCM Source" case, I think this could use SCMHead.HeadByItem.findHead(Item item) and then SCMHead.getName(). Perhaps there is an alternative approach via branch-api-plugin, as well. For the "Multibranch Pipeline Job built with an SCMStep" case, I am not sure how this should be done.
            sam117 Viktor Sam added a comment - - edited https://github.com/jenkinsci/atlassian-bitbucket-server-integration-plugin/blob/bce76f1f76daff3fb587ca94cb0c2208b8afc71e/src/main/java/com/atlassian/bitbucket/jenkins/internal/link/BitbucketExternalLinkUtils.java#L44 maybe branch.toString() or use  java.net.URLDecoder   may be helpful?

            The "Multibranch Pipeline Job built with an SCMStep" case apparently refers to com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMStep ("bbs_checkout" in pipeline; source) or org.jenkinsci.plugins.workflow.steps.scm.GenericSCMStep ("checkout" in pipeline; source), which extend org.jenkinsci.plugins.workflow.steps.scm.SCMStep (source). (jenkins.plugins.git.GitStep ("git" in pipeline; source) likewise extends it, but it is a final class and its createSCM() method creates an instance of GitSCM, which would not pass the scm instanceof BitbucketSCM check.)

            I think it should somehow use the branches that were checked out by those steps, but it is not clear to me how to do this because BitbucketSCM.branches lists branch specs rather than branches, and they can have wildcards in them.

            kon Kalle Niemitalo added a comment - The "Multibranch Pipeline Job built with an SCMStep" case apparently refers to com.atlassian.bitbucket.jenkins.internal.scm.BitbucketSCMStep ("bbs_checkout" in pipeline; source ) or org.jenkinsci.plugins.workflow.steps.scm.GenericSCMStep ("checkout" in pipeline; source ), which extend org.jenkinsci.plugins.workflow.steps.scm.SCMStep ( source ). (jenkins.plugins.git.GitStep ("git" in pipeline; source ) likewise extends it, but it is a final class and its createSCM() method creates an instance of GitSCM, which would not pass the scm instanceof BitbucketSCM check.) I think it should somehow use the branches that were checked out by those steps, but it is not clear to me how to do this because BitbucketSCM.branches lists branch specs rather than branches, and they can have wildcards in them.

            https://github.com/jenkinsci/atlassian-bitbucket-server-integration-plugin/blob/bce76f1f76daff3fb587ca94cb0c2208b8afc71e/src/main/java/com/atlassian/bitbucket/jenkins/internal/link/BitbucketExternalLinkUtils.java#L44

            Well, the parameter of BitbucketExternalLinkUtils.createBranchDiffLink is String branch rather than String job, so I think this should be kept as is and the caller should be changed.

            maybe +branch.toString()

            Would have no effect because it's already a String.

            or use +java.net.URLDecoder may be helpful?

            If you were going to explicitly decode the job name to a branch name, then that should be done using jenkins.branch.NameEncoder, for consistency with MultiBranchProject.getItemByBranchName. However, because BitbucketJobLinkActionFactory gets the repository information from the BitbucketSCM and BitbucketSCMSource instances, it should get the branch names from those as well, instead of assuming that the branch names have anything to do with the job name.

            kon Kalle Niemitalo added a comment - https://github.com/jenkinsci/atlassian-bitbucket-server-integration-plugin/blob/bce76f1f76daff3fb587ca94cb0c2208b8afc71e/src/main/java/com/atlassian/bitbucket/jenkins/internal/link/BitbucketExternalLinkUtils.java#L44 Well, the parameter of BitbucketExternalLinkUtils.createBranchDiffLink is String branch rather than String job , so I think this should be kept as is and the caller should be changed. maybe +branch.toString() Would have no effect because it's already a String. or use +java.net.URLDecoder may be helpful? If you were going to explicitly decode the job name to a branch name, then that should be done using jenkins.branch.NameEncoder , for consistency with MultiBranchProject.getItemByBranchName . However, because BitbucketJobLinkActionFactory gets the repository information from the BitbucketSCM and BitbucketSCMSource instances, it should get the branch names from those as well, instead of assuming that the branch names have anything to do with the job name.

            Related code in the Bitbucket Branch Source plugin: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/c79f7c340cac7455b90d963bdaba9f4fb7dd2c25/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java#L1051-L1076

            It just operates based on the SCMHead and does not try to generate sidebar links based on SCM instances. Which makes sense because this code is in BitbucketSCMSource.retrieveActions, which overrides SCMSource.retrieveActions. In contrast, the Bitbucket Server Integration plugin generates sidebar links in BitbucketJobLinkActionFactory, which implements the TransientActionFactory extension point so it can be called even without an SCMSource.

            The Bitbucket Branch Source plugin also creates BitbucketLink instances in the BitbucketSCMNavigator.retrieveActions method. The BitbucketSCMNavigator class is for things that contain multiple repositories, like projects in Bitbucket Server or workspaces in Bitbucket Cloud. So, that one does not generate sidebar links from SCM instances, either.

            kon Kalle Niemitalo added a comment - Related code in the Bitbucket Branch Source plugin: https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/c79f7c340cac7455b90d963bdaba9f4fb7dd2c25/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java#L1051-L1076 It just operates based on the SCMHead and does not try to generate sidebar links based on SCM instances. Which makes sense because this code is in BitbucketSCMSource.retrieveActions, which overrides SCMSource.retrieveActions. In contrast, the Bitbucket Server Integration plugin generates sidebar links in BitbucketJobLinkActionFactory, which implements the TransientActionFactory extension point so it can be called even without an SCMSource. The Bitbucket Branch Source plugin also creates BitbucketLink instances in the BitbucketSCMNavigator.retrieveActions method. The BitbucketSCMNavigator class is for things that contain multiple repositories, like projects in Bitbucket Server or workspaces in Bitbucket Cloud. So, that one does not generate sidebar links from SCM instances, either.
            sam117 Viktor Sam added a comment - - edited

            kon, I think you are wright about jenkins.branch.NameEncoder. I have simmilar issue with Jira steps plugin
            In comment footer plugin adds same %252F instead of %2F. But i have not anough expirience in java to discover root issue
            This switch key could be the reason

            sam117 Viktor Sam added a comment - - edited kon , I think you are wright about  jenkins.branch.NameEncoder.  I have simmilar issue with Jira steps plugin In comment footer  plugin adds same %252F  instead of %2F. But i have not anough expirience in java to discover root issue This switch key could be the reason

            People

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

              Dates

                Created:
                Updated:
                Resolved: