Skip to content

Commit 6ca2b14

Browse files
fix: write dynamic-stack teardown status to a file for reliable pipeline reporting
The teardown shutdown hook's stdout doesn't reliably reach maven_output.log (observed locally and on GoCD), so Slack summaries reported 'stack NOT deleted' even when deletion succeeded. Teardown now writes dynamic-stack-status.txt (deleted/preserved/delete-failed) which pipelines read instead of grepping logs.
1 parent 8182945 commit 6ca2b14

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,4 @@ src/main/resources/
273273
/.vscode/
274274
.env
275275

276+
dynamic-stack-status.txt

src/test/java/com/contentstack/cms/TestStackContext.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public static synchronized void teardown() {
160160
System.out.println("[TestStackContext] API key: " + stackApiKey);
161161
System.out.println("[TestStackContext] Management token: " + managementToken);
162162
System.out.println("[TestStackContext] Remember to delete it manually when done!");
163+
writeStatusFile("preserved " + stackName + " " + stackApiKey);
163164
return;
164165
}
165166

@@ -173,14 +174,32 @@ public static synchronized void teardown() {
173174
try (Response response = http.newCall(request).execute()) {
174175
if (response.isSuccessful()) {
175176
System.out.println("[TestStackContext] Deleted test stack: " + stackName);
177+
writeStatusFile("deleted " + stackName);
176178
} else {
177179
System.err.println("[TestStackContext] Stack deletion failed with " + response.code()
178180
+ " - delete manually: " + stackName + " (" + stackApiKey + ")");
181+
writeStatusFile("delete-failed " + stackName + " " + stackApiKey);
179182
}
180183
}
181184
} catch (Exception e) {
182185
System.err.println("[TestStackContext] Stack deletion error: " + e.getMessage()
183186
+ " - delete manually: " + stackName + " (" + stackApiKey + ")");
187+
writeStatusFile("delete-failed " + stackName + " " + stackApiKey);
188+
}
189+
}
190+
191+
/**
192+
* Writes the teardown outcome to a file in the working directory. The
193+
* shutdown hook's stdout doesn't reliably reach the surefire/maven log
194+
* (observed both locally and on GoCD), so pipelines read this file to
195+
* report whether the dynamic stack was cleaned up.
196+
*/
197+
private static void writeStatusFile(String status) {
198+
try {
199+
java.nio.file.Files.write(java.nio.file.Paths.get("dynamic-stack-status.txt"),
200+
(status + System.lineSeparator()).getBytes(java.nio.charset.StandardCharsets.UTF_8));
201+
} catch (Exception e) {
202+
// best effort only
184203
}
185204
}
186205

0 commit comments

Comments
 (0)