From 26b5ccdff06613f86b7f72b8e63e2bd2a7b836a8 Mon Sep 17 00:00:00 2001 From: Simon Bennetts Date: Fri, 29 Nov 2024 16:44:42 +0000 Subject: [PATCH] Automation: added method for setting exit value Signed-off-by: Simon Bennetts --- addOns/automation/CHANGELOG.md | 1 + .../addon/automation/ExtensionAutomation.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/addOns/automation/CHANGELOG.md b/addOns/automation/CHANGELOG.md index 8e70877bbfc..e9cbdedfad3 100644 --- a/addOns/automation/CHANGELOG.md +++ b/addOns/automation/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Active scan policy job. - Add job to configure the active scanner, `activeScan-config`. - Allow to enable/disable jobs (Issue 5845). +- Method to allow the user to set the exit code via a script. ### Changed - Updated automation framework documentation and templates for `activeScan` job to reflect changes to the default value of threadPerHost parameter diff --git a/addOns/automation/src/main/java/org/zaproxy/addon/automation/ExtensionAutomation.java b/addOns/automation/src/main/java/org/zaproxy/addon/automation/ExtensionAutomation.java index 712cf04c29e..3d6ee873a5c 100644 --- a/addOns/automation/src/main/java/org/zaproxy/addon/automation/ExtensionAutomation.java +++ b/addOns/automation/src/main/java/org/zaproxy/addon/automation/ExtensionAutomation.java @@ -114,6 +114,8 @@ public class ExtensionAutomation extends ExtensionAdaptor implements CommandLine private AutomationPanel automationPanel; + private Integer exitOverride; + public ExtensionAutomation() { super(NAME); setI18nPrefix(PREFIX); @@ -696,13 +698,23 @@ private void runPlanCommandLine(String source) { } AutomationProgress progress = runAutomationFile(source); - if (progress == null || progress.hasErrors()) { + if (exitOverride != null) { + setExitStatus(exitOverride, "set by user", false); + } else if (progress == null || progress.hasErrors()) { setExitStatus(1, "plan errors", false); } else if (progress.hasWarnings()) { setExitStatus(2, "plan warnings", false); } } + public Integer getExitOverride() { + return exitOverride; + } + + public void setExitOverride(Integer exitOverride) { + this.exitOverride = exitOverride; + } + private static URI createUri(String source) { try { new java.net.URI(source).toURL();