environmentVariables) throws Exception {
+
+ // Create a thread to run Katalon execution
+ final Exception[] executionException = new Exception[1];
+ final Boolean[] result = new Boolean[1];
+
+ Thread katalonThread = new Thread(() -> {
+ try {
+ result[0] = KatalonUtils.executeKatalon(
+ logger, version, location, workspaceLocation,
+ executeArgs, x11Display, xvfbConfiguration, environmentVariables);
+ } catch (Exception e) {
+ executionException[0] = e;
+ }
+ });
+
+ katalonThread.start();
+
+ // Monitor for interruption while Katalon is running
+ while (katalonThread.isAlive()) {
+ if (Thread.currentThread().isInterrupted()) {
+ logger.info("Build cancellation detected, force stopping Katalon execution");
+
+ // Force kill Katalon processes
+ forceStopKatalonProcesses(logger);
+
+ // Interrupt the Katalon thread
+ katalonThread.interrupt();
+
+ // Wait a bit for graceful shutdown
+ try {
+ katalonThread.join(3000); // Wait up to 3 seconds
+ } catch (InterruptedException ie) {
+ // If we're interrupted while waiting, force stop
+ Thread.currentThread().interrupt();
+ }
+ throw new InterruptedException("Katalon execution was forcibly cancelled");
+ }
+
+ try {
+ Thread.sleep(500); // Check every 0.5 seconds for faster response
+ } catch (InterruptedException e) {
+ // If interrupted while sleeping, force stop Katalon and exit
+ forceStopKatalonProcesses(logger);
+ katalonThread.interrupt();
+ throw e;
+ }
+ }
+ // Check if there was an exception during execution
+ if (executionException[0] != null) {
+ throw executionException[0];
+ }
+ return result[0] != null ? result[0] : false;
+ }
+
+ private void forceStopKatalonProcesses(Logger logger) {
+ try {
+ String os = System.getProperty("os.name").toLowerCase();
+
+ if (os.contains("win")) {
+ // Windows - kill Katalon processes
+ executeCommand(new String[] { "taskkill", "/F", "/IM", "katalonc.exe" }, logger);
+ } else {
+ // Linux/Unix - kill Katalon processes
+ executeCommand(new String[] { "pkill", "-f", "katalonc" }, logger);
+ // Force kill if regular kill doesn't work
+ executeCommand(new String[] { "pkill", "-9", "-f", "katalonc" }, logger);
+ }
+ } catch (Exception e) {
+ logger.info("Error while trying to force stop Katalon processes: " + e.getMessage());
+ }
+ }
+
+ private void executeCommand(String[] command, Logger logger) {
+ try {
+ ProcessBuilder pb = new ProcessBuilder(command);
+ pb.redirectErrorStream(true);
+ Process process = pb.start();
+
+ // Wait for command to complete (with timeout)
+ boolean finished = process.waitFor(5, java.util.concurrent.TimeUnit.SECONDS);
+
+ if (!finished) {
+ logger.info("Force stop command timed out: " + String.join(" ", command));
+ process.destroyForcibly();
+ } else {
+ int exitCode = process.exitValue();
+ logger.info("Force stop command completed with exit code " + exitCode + ": "
+ + String.join(" ", command));
+ }
+ } catch (Exception e) {
+ logger.info(
+ "Failed to execute force stop command: " + String.join(" ", command) + " - " + e.getMessage());
+ }
+ }
+ }
}
diff --git a/src/main/resources/index.jelly b/src/main/resources/index.jelly
new file mode 100644
index 0000000..679377c
--- /dev/null
+++ b/src/main/resources/index.jelly
@@ -0,0 +1,4 @@
+
+
+ Execute Katalon Studio in Jenkins
+
\ No newline at end of file