Skip to content

Commit

Permalink
[JENKINS-73471] Git scm.userRemoteConfigs.credentialsId configured by…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
nfalco79 authored Nov 3, 2024
1 parent 6e501b9 commit cb6984f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,12 @@ private BitbucketCommit findPRDestinationCommit(BitbucketPullRequest pr, TaskLis
public SCM build(SCMHead head, SCMRevision revision) {
initCloneLinks();

boolean sshAuth = traits.stream()
.anyMatch(SSHCheckoutTrait.class::isInstance);

BitbucketAuthenticator authenticator = authenticator();
return new BitbucketGitSCMBuilder(this, head, revision, null)
.withExtension(authenticator == null ? null : new GitClientAuthenticatorExtension(authenticator.getCredentialsForScm()))
.withExtension(authenticator == null || sshAuth ? null : new GitClientAuthenticatorExtension(authenticator.getCredentialsForSCM()))

Check warning on line 973 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketSCMSource.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 973 is only partially covered, 3 branches are missing
.withCloneLinks(primaryCloneLinks, mirrorCloneLinks)
.withTraits(traits)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void configureRequest(HttpRequest request) {
*
* @return credentials to be passed to {@link org.jenkinsci.plugins.gitclient.GitClient#setCredentials(StandardUsernameCredentials)}
*/
public StandardUsernameCredentials getCredentialsForScm() {
public StandardUsernameCredentials getCredentialsForSCM() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public void configureRequest(HttpRequest request) {
}

@Override
public StandardUsernameCredentials getCredentialsForScm() {
public StandardUsernameCredentials getCredentialsForSCM() {
try {
return new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL, null, null, StringUtils.EMPTY, token.getPlainText());
CredentialsScope.GLOBAL, getId(), null, StringUtils.EMPTY, token.getPlainText());

Check warning on line 44 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketAccessTokenAuthenticator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 44 is not covered by tests
} catch (FormException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public void configureRequest(HttpRequest request) {
}

@Override
public StandardUsernameCredentials getCredentialsForScm() {
public StandardUsernameCredentials getCredentialsForSCM() {
try {
return new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL, null, null, StringUtils.EMPTY, token.getToken());
CredentialsScope.GLOBAL, getId(), null, StringUtils.EMPTY, token.getToken());

Check warning on line 46 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketOAuthAuthenticator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 46 is not covered by tests
} catch (FormException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public void configureContext(HttpClientContext context, HttpHost host) {
}

@Override
public StandardUsernameCredentials getCredentialsForScm() {
public StandardUsernameCredentials getCredentialsForSCM() {
try {
return new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL, null, null, httpCredentials.getUserName(), httpCredentials.getPassword());
CredentialsScope.GLOBAL, getId(), null, httpCredentials.getUserName(), httpCredentials.getPassword());

Check warning on line 86 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/credentials/BitbucketUsernamePasswordAuthenticator.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 86 is not covered by tests
} catch (FormException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit cb6984f

Please # to comment.