Skip to content

Save EC2 cloud when error code is ExpiredToken #1084

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions src/main/java/hudson/plugins/ec2/EC2Cloud.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,14 +1047,22 @@
}
} catch (AwsServiceException e) {
LOGGER.log(Level.WARNING, t + ". Exception during provisioning", e);
if (e.awsErrorDetails().errorCode().equals("RequestExpired")
|| e.awsErrorDetails().errorCode().equals("ExpiredToken")) {
// A RequestExpired or ExpiredToken error can indicate that credentials have expired so reconnect
LOGGER.log(Level.INFO, "Reconnecting to EC2 due to RequestExpired or ExpiredToken error");
if (e.awsErrorDetails().errorCode().equals("RequestExpired")) {
// A RequestExpired error can indicate that request has expired so reconnect
LOGGER.log(Level.INFO, "Reconnecting to EC2 due to RequestExpired error");
try {
reconnectToEc2();
} catch (IOException e2) {
LOGGER.log(Level.WARNING, "Failed to reconnect ec2", e2);
LOGGER.log(Level.WARNING, "Failed to reconnect EC2", e2);
}
} else if (e.awsErrorDetails().errorCode().equals("ExpiredToken")) {
// A ExpiredToken error can indicate that token has expired so re-save the cloud
LOGGER.log(Level.INFO, "Re-saving EC2 cloud due to ExpiredToken error");
try {
Jenkins.get().clouds.replace(this, this);
Jenkins.get().save();
} catch (IOException e2) {
LOGGER.log(Level.WARNING, "Failed to re-save EC2 cloud: " + getCloudName(), e2);

Check warning on line 1065 in src/main/java/hudson/plugins/ec2/EC2Cloud.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 1050-1065 are not covered by tests
}
}
} catch (SdkException | IOException e) {
Expand Down