Skip to content

Commit

Permalink
[JENKINS-644418] Add exponential backoff to BitBucket rate limit retr…
Browse files Browse the repository at this point in the history
…y loop

Configure Apache HTTP client to use an exponential backoff retry strategy
  • Loading branch information
nfalco79 committed Nov 27, 2024
1 parent a71d0e0 commit d8491ae
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 525 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ work

# VSCode
.factorypath
META-INF/
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ private static void createStatus(@NonNull Run<?, ?> build, @NonNull TaskListener

private static @CheckForNull BitbucketSCMSource findBitbucketSCMSource(Run<?, ?> build) {
SCMSource s = SCMSource.SourceByItem.findSource(build.getParent());
return s instanceof BitbucketSCMSource ? (BitbucketSCMSource) s : null;
return s instanceof BitbucketSCMSource scm ? scm : null;
}

private static void sendNotifications(BitbucketSCMSource source, Run<?, ?> build, TaskListener listener)
Expand Down Expand Up @@ -211,12 +211,11 @@ private static void sendNotifications(BitbucketSCMSource source, Run<?, ?> build

@CheckForNull
private static String getHash(@CheckForNull SCMRevision revision) {
if (revision instanceof PullRequestSCMRevision) {
// unwrap
revision = ((PullRequestSCMRevision) revision).getPull();
if (revision instanceof PullRequestSCMRevision prRevision) {
revision = prRevision.getPull();
}
if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
return ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash();
if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl scmRevision) {
return scmRevision.getHash();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,15 +1002,15 @@ private BitbucketCommit findPRDestinationCommit(BitbucketPullRequest pr, TaskLis
public SCM build(SCMHead head, SCMRevision revision) {
initCloneLinks();

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

BitbucketAuthenticator authenticator = authenticator();
GitSCMExtension scmExtension;
if (authenticator != null) {
// workaround to force git-plugin to use the configured username/password credentialsId as is
// remove this workaround as https://github.com/jenkinsci/bitbucket-branch-source-plugin/pull/867 will be merged
boolean sshAuth = traits.stream()
.anyMatch(SSHCheckoutTrait.class::isInstance);
if (sshAuth) {
// trait will do the magic
scmCredentialsId = null;
Expand All @@ -1027,8 +1027,8 @@ public SCM build(SCMHead head, SCMRevision revision) {
scmExtension = new GitClientAuthenticatorExtension(null);
}

return new BitbucketGitSCMBuilder(this, head, revision, scmCredentialsId)
.withExtension(scmExtension)
return new BitbucketGitSCMBuilder(this, head, revision, null)
.withExtension(new GitClientAuthenticatorExtension(authenticator == null || sshAuth ? null : authenticator.getCredentialsForSCM()))
.withCloneLinks(primaryCloneLinks, mirrorCloneLinks)
.withTraits(traits)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package com.cloudbees.jenkins.plugins.bitbucket.api;

import com.fasterxml.jackson.annotation.JsonIgnore;
import edu.umd.cs.findbugs.annotations.NonNull;
import org.apache.commons.codec.digest.DigestUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
Expand Down Expand Up @@ -99,6 +100,20 @@ public BitbucketBuildStatus(String hash, String description, Status state, Strin
this.name = name;
}

/**
* Copy constructor.
*
* @param other from copy to.
*/
public BitbucketBuildStatus(@NonNull BitbucketBuildStatus other) {
this.hash = other.hash;
this.description = other.description;
this.state = other.state;
this.url = other.url;
this.key = other.key;
this.name = other.name;
}

public String getHash() {
return hash;
}
Expand Down
Loading

0 comments on commit d8491ae

Please sign in to comment.