Skip to content

Commit 4a79ab9

Browse files
authored
Get fresh oauth token on every git clone (#824)
Previously token was fetched only once and saved in BitbucketSCMSource. Fixes #808. See also #810 and #796.
1 parent bbd5243 commit 4a79ab9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package com.cloudbees.jenkins.plugins.bitbucket;
2525

26+
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketAuthenticator;
2627
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketHref;
2728
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepository;
2829
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketRepositoryProtocol;
@@ -309,6 +310,13 @@ private String getCloneLink(List<BitbucketHref> cloneLinks) {
309310
return cloneLinks.stream()
310311
.filter(link -> protocol.matches(link.getName()))
311312
.findAny()
313+
.map(bitbucketHref -> {
314+
BitbucketAuthenticator authenticator = scmSource().authenticator();
315+
if (authenticator == null) {
316+
return bitbucketHref;
317+
}
318+
return authenticator.addAuthToken(bitbucketHref);
319+
})
312320
.orElseThrow(() -> new IllegalStateException("Can't find clone link for protocol " + protocol))
313321
.getHref();
314322
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686
import java.util.concurrent.ConcurrentHashMap;
8787
import java.util.logging.Level;
8888
import java.util.logging.Logger;
89-
import java.util.stream.Collectors;
9089
import jenkins.authentication.tokens.api.AuthenticationTokens;
9190
import jenkins.model.Jenkins;
9291
import jenkins.plugins.git.AbstractGitSCMSource.SCMRevisionImpl;
@@ -1039,12 +1038,7 @@ public SCM build(SCMHead head, SCMRevision revision) {
10391038
}
10401039

10411040
private void setPrimaryCloneLinks(List<BitbucketHref> links) {
1042-
BitbucketAuthenticator authenticator = authenticator();
1043-
if (authenticator == null) {
1044-
primaryCloneLinks = links;
1045-
} else {
1046-
primaryCloneLinks = links.stream().map(authenticator::addAuthToken).collect(Collectors.toList());
1047-
}
1041+
primaryCloneLinks = links;
10481042
}
10491043

10501044
@NonNull

0 commit comments

Comments
 (0)