Skip to content

[JENKINS-75611] Disabling HTTPS cloning protocol on Data Center causes builds to fail even if SSH checkout feature is configured #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private void withPullRequestRemote(PullRequestSCMHead head, String headName) { /
}

@NonNull
public String getCloudRepositoryUri(@NonNull String owner, @NonNull String repository) {
private String getCloudRepositoryUri(@NonNull String owner, @NonNull String repository) {
switch (protocol) {
case HTTP:
return "https://bitbucket.org/" + owner + "/" + repository + ".git";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
package com.cloudbees.jenkins.plugins.bitbucket;

import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketCommit;
import com.fasterxml.jackson.databind.util.StdDateFormat;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.text.ParseException;
import java.util.Date;
import java.util.Objects;
import jenkins.plugins.git.AbstractGitSCMSource.SCMRevisionImpl;
Expand Down Expand Up @@ -55,15 +53,7 @@ public BitbucketGitSCMRevision(@NonNull SCMHead head, @NonNull BitbucketCommit c
super(head, commit.getHash());
this.message = commit.getMessage();
this.author = commit.getAuthor();
Date commitDate = null;
try {
if (commit.getDate() != null) {
commitDate = new StdDateFormat().parse(commit.getDate());
}
} catch (ParseException e) {
commitDate = null;
}
this.date = commitDate;
this.date = commit.getCommitterDate();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
Expand Down Expand Up @@ -721,17 +722,21 @@ private BitbucketCommit findPRDestinationCommit(BitbucketPullRequest pr, TaskLis
public SCM build(@NonNull SCMHead head, @CheckForNull SCMRevision revision) {
initCloneLinks();

BitbucketGitSCMBuilder scmBuilder = new BitbucketGitSCMBuilder(this, head, revision, credentialsId)
SSHCheckoutTrait sshTrait = SCMTrait.find(traits, SSHCheckoutTrait.class);
String checkoutCredentialsId = sshTrait != null ? sshTrait.getCredentialsId() : credentialsId;

BitbucketGitSCMBuilder scmBuilder = new BitbucketGitSCMBuilder(this, head, revision, checkoutCredentialsId)
.withExtension(new BitbucketEnvVarExtension(getRepoOwner(), getRepository(), getProjectKey(), getServerUrl()))
.withCloneLinks(primaryCloneLinks, mirrorCloneLinks)
.withTraits(traits);

boolean sshAuth = SCMTrait.find(traits, SSHCheckoutTrait.class) != null;

SCMSourceOwner owner = getOwner();
String scmOwner = owner != null ? owner.getFullName() : null;
// checkoutURL must be calculated after set withCloneLinks and credentials
String checkoutURL = scmBuilder.remote();
String scmOwner = Optional.ofNullable(getOwner())
.map(SCMSourceOwner::getFullName)
.orElse(null);
return scmBuilder
.withExtension(new GitClientAuthenticatorExtension(scmBuilder.remote(), serverUrl, scmOwner, sshAuth ? null : credentialsId))
.withExtension(new GitClientAuthenticatorExtension(checkoutURL, serverUrl, scmOwner, sshTrait != null ? null : checkoutCredentialsId))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ default StandardUsernameCredentials getCredentialsForSCM() {
* Generates context that sub-classes can use to determine if they would be able to authenticate against the
* provided server.
*
* @param serverUrl The URL being authenticated against
* @param serverURL The URL being authenticated against
* @return an {@link AuthenticationTokenContext} for use with the AuthenticationTokens APIs
*/
public static AuthenticationTokenContext<BitbucketAuthenticator> authenticationContext(String serverUrl) {
if (serverUrl == null) {
serverUrl = BitbucketCloudEndpoint.SERVER_URL;
public static AuthenticationTokenContext<BitbucketAuthenticator> authenticationContext(String serverURL) {
if (serverURL == null) {
serverURL = BitbucketCloudEndpoint.SERVER_URL;
}

String scheme = serverUrl.split(":")[0].toLowerCase();
boolean isCloud = BitbucketApiUtils.isCloud(serverUrl);
String scheme = serverURL.split(":")[0].toLowerCase();
boolean isCloud = BitbucketApiUtils.isCloud(serverURL);

return AuthenticationTokenContext.builder(BitbucketAuthenticator.class)
.with(SERVER_URL, serverUrl)
.with(SERVER_URL, serverURL)
.with(SCHEME, scheme)
.with(BITBUCKET_INSTANCE_TYPE, isCloud ? BITBUCKET_INSTANCE_TYPE_CLOUD : BITBUCKET_INSTANCE_TYPE_SERVER)
.build();
Expand Down
Loading