Skip to content

Commit 7d026be

Browse files
committed
[JENKINS-75015] Update the build status refname format used for Bitbucket Cloud (#947)
1 parent 4b6002a commit 7d026be

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/notifier/BitbucketBuildStatusNotifications.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,16 @@ private static void sendNotifications(BitbucketSCMSource source, Run<?, ?> build
234234
listener.getLogger().println("[Bitbucket] Notifying commit build result");
235235
SCMHead head = rev.getHead();
236236
key = getBuildKey(build, head.getName(), shareBuildKeyBetweenBranchAndPR);
237-
if (rev instanceof BitbucketTagSCMRevision || head instanceof BitbucketTagSCMHead) {
238-
refName = "refs/tags/" + head.getName();
237+
bitbucket = source.buildBitbucketClient();
238+
if (BitbucketApiUtils.isCloud(bitbucket)) {
239+
refName = head.getName();
239240
} else {
240-
refName = "refs/heads/" + head.getName();
241+
if (rev instanceof BitbucketTagSCMRevision || head instanceof BitbucketTagSCMHead) {
242+
refName = "refs/tags/" + head.getName();
243+
} else {
244+
refName = "refs/heads/" + head.getName();
245+
}
241246
}
242-
bitbucket = source.buildBitbucketClient();
243247
}
244248
createStatus(build, listener, bitbucket, key, hash, refName);
245249
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/util/BitbucketApiUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApiFactory;
66
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
77
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRequestException;
8+
import com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient;
89
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketCloudEndpoint;
910
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;
1011
import com.cloudbees.plugins.credentials.CredentialsProvider;
@@ -26,7 +27,11 @@
2627
@Restricted(NoExternalUse.class)
2728
public class BitbucketApiUtils {
2829

29-
private static final Logger LOGGER = Logger.getLogger(BitbucketApiUtils.class.getName());
30+
private static final Logger logger = Logger.getLogger(BitbucketApiUtils.class.getName());
31+
32+
public static boolean isCloud(BitbucketApi client) {
33+
return client instanceof BitbucketCloudApiClient;
34+
}
3035

3136
public static ListBoxModel getFromBitbucket(SCMSourceOwner context,
3237
String serverUrl,
@@ -82,10 +87,10 @@ public static ListBoxModel getFromBitbucket(SCMSourceOwner context,
8287
: Messages.BitbucketSCMSource_UnauthorizedOwner(repoOwner)).withSelectionCleared();
8388
}
8489
}
85-
LOGGER.log(Level.SEVERE, e.getMessage(), e);
90+
logger.log(Level.SEVERE, e.getMessage(), e);
8691
throw FormFillFailure.error(e.getMessage());
8792
} catch (Throwable e) {
88-
LOGGER.log(Level.SEVERE, e.getMessage(), e);
93+
logger.log(Level.SEVERE, e.getMessage(), e);
8994
throw FormFillFailure.error(e.getMessage());
9095
}
9196
}

0 commit comments

Comments
 (0)