Skip to content

Commit

Permalink
Revert "ComputeEnginerInstance terminate instance without checking if…
Browse files Browse the repository at this point in the history
… it still exists."

This reverts commit f6fc88c.
  • Loading branch information
Artmorse committed Dec 11, 2024
1 parent ce2791c commit d811f6c
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,16 @@ protected void _terminate(TaskListener listener) throws IOException, Interrupted
.createSnapshotSync(cloud.getProjectId(), this.zone, this.getNodeName(), createSnapshotTimeout);
}

Map<String, String> filterLabel = ImmutableMap.of(CLOUD_ID_LABEL_KEY, cloud.getInstanceId());
var instanceExistsInCloud =
cloud.getClient().listInstancesWithLabel(cloud.getProjectId(), filterLabel).stream()
.anyMatch(instance -> instance.getName().equals(name));

// If the instance exists in the cloud, attempt to terminate it. This is an async call and we
// return immediately, hoping for the best.
cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name);
if (instanceExistsInCloud) {

Check warning on line 144 in src/main/java/com/google/jenkins/plugins/computeengine/ComputeEngineInstance.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 137-144 are not covered by tests
cloud.getClient().terminateInstanceAsync(cloud.getProjectId(), zone, name);
}
} catch (CloudNotFoundException cnfe) {
listener.error(cnfe.getMessage());
} catch (OperationException oe) {
Expand Down

0 comments on commit d811f6c

Please sign in to comment.