Skip to content

Commit 94d2883

Browse files
authored
[JENKINS-73012] The URL generated to link the tag job to Bitbucket Cloud is wrong (jenkinsci#992)
Fix the URL generated in BitbucketLink and ObjectMetadataAction for job of kind tag
1 parent fef5008 commit 94d2883

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
import java.util.logging.Logger;
9797
import jenkins.authentication.tokens.api.AuthenticationTokens;
9898
import jenkins.model.Jenkins;
99+
import jenkins.plugins.git.GitTagSCMHead;
99100
import jenkins.plugins.git.traits.GitBrowserSCMSourceTrait;
100101
import jenkins.scm.api.SCMHead;
101102
import jenkins.scm.api.SCMHeadCategory;
@@ -1135,15 +1136,24 @@ protected List<Action> retrieveActions(@NonNull SCMHead head,
11351136
List<Action> result = new ArrayList<>();
11361137
UriTemplate template;
11371138
String title = null;
1138-
if (BitbucketCloudEndpoint.SERVER_URL.equals(getServerUrl())) {
1139-
template = UriTemplate.fromTemplate(getServerUrl() + CLOUD_REPO_TEMPLATE + "/{branchOrPR}/{prIdOrHead}")
1140-
.set("owner", repoOwner)
1141-
.set("repo", repository);
1139+
if (BitbucketApiUtils.isCloud(getServerUrl())) {
1140+
String resourceName;
1141+
String resourceId;
11421142
if (head instanceof PullRequestSCMHead prHead) {
1143-
template.set("branchOrPR", "pull-requests").set("prIdOrHead", prHead.getId());
1143+
resourceName = "pull-requests";
1144+
resourceId = prHead.getId();
1145+
} else if (head instanceof GitTagSCMHead) {
1146+
resourceName = "commits";
1147+
resourceId = head.getName();
11441148
} else {
1145-
template.set("branchOrPR", "branch").set("prIdOrHead", head.getName());
1149+
resourceName = "branch";
1150+
resourceId = head.getName();
11461151
}
1152+
template = UriTemplate.fromTemplate(getServerUrl() + CLOUD_REPO_TEMPLATE + "/{resourceName}/{resourceId}")
1153+
.set("owner", repoOwner)
1154+
.set("repo", repository)
1155+
.set("resourceName", resourceName)
1156+
.set("resourceId", resourceId);
11471157
} else {
11481158
if (head instanceof PullRequestSCMHead prHead) {
11491159
template = UriTemplate

0 commit comments

Comments
 (0)