Skip to content

Commit cb6984f

Browse files
authored
[JENKINS-73471] Git scm.userRemoteConfigs.credentialsId configured by Bitbucket is null (#899)
Set the credentialsId returned by the authenticator for SCM. In case of SSH Trait is set git SCM credential to null to re-apply patch jenkinsci/git-plugin#1649
1 parent 6e501b9 commit cb6984f

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,9 +965,12 @@ private BitbucketCommit findPRDestinationCommit(BitbucketPullRequest pr, TaskLis
965965
public SCM build(SCMHead head, SCMRevision revision) {
966966
initCloneLinks();
967967

968+
boolean sshAuth = traits.stream()
969+
.anyMatch(SSHCheckoutTrait.class::isInstance);
970+
968971
BitbucketAuthenticator authenticator = authenticator();
969972
return new BitbucketGitSCMBuilder(this, head, revision, null)
970-
.withExtension(authenticator == null ? null : new GitClientAuthenticatorExtension(authenticator.getCredentialsForScm()))
973+
.withExtension(authenticator == null || sshAuth ? null : new GitClientAuthenticatorExtension(authenticator.getCredentialsForSCM()))
971974
.withCloneLinks(primaryCloneLinks, mirrorCloneLinks)
972975
.withTraits(traits)
973976
.build();

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/BitbucketAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void configureRequest(HttpRequest request) {
114114
*
115115
* @return credentials to be passed to {@link org.jenkinsci.plugins.gitclient.GitClient#setCredentials(StandardUsernameCredentials)}
116116
*/
117-
public StandardUsernameCredentials getCredentialsForScm() {
117+
public StandardUsernameCredentials getCredentialsForSCM() {
118118
return null;
119119
}
120120

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketAccessTokenAuthenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public void configureRequest(HttpRequest request) {
3838
}
3939

4040
@Override
41-
public StandardUsernameCredentials getCredentialsForScm() {
41+
public StandardUsernameCredentials getCredentialsForSCM() {
4242
try {
4343
return new UsernamePasswordCredentialsImpl(
44-
CredentialsScope.GLOBAL, null, null, StringUtils.EMPTY, token.getPlainText());
44+
CredentialsScope.GLOBAL, getId(), null, StringUtils.EMPTY, token.getPlainText());
4545
} catch (FormException e) {
4646
throw new RuntimeException(e);
4747
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuthAuthenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public void configureRequest(HttpRequest request) {
4040
}
4141

4242
@Override
43-
public StandardUsernameCredentials getCredentialsForScm() {
43+
public StandardUsernameCredentials getCredentialsForSCM() {
4444
try {
4545
return new UsernamePasswordCredentialsImpl(
46-
CredentialsScope.GLOBAL, null, null, StringUtils.EMPTY, token.getToken());
46+
CredentialsScope.GLOBAL, getId(), null, StringUtils.EMPTY, token.getToken());
4747
} catch (FormException e) {
4848
throw new RuntimeException(e);
4949
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketUsernamePasswordAuthenticator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public void configureContext(HttpClientContext context, HttpHost host) {
8080
}
8181

8282
@Override
83-
public StandardUsernameCredentials getCredentialsForScm() {
83+
public StandardUsernameCredentials getCredentialsForSCM() {
8484
try {
8585
return new UsernamePasswordCredentialsImpl(
86-
CredentialsScope.GLOBAL, null, null, httpCredentials.getUserName(), httpCredentials.getPassword());
86+
CredentialsScope.GLOBAL, getId(), null, httpCredentials.getUserName(), httpCredentials.getPassword());
8787
} catch (FormException e) {
8888
throw new RuntimeException(e);
8989
}

0 commit comments

Comments
 (0)