This is an automated email from the ASF dual-hosted git repository.

bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git


The following commit(s) were added to refs/heads/main by this push:
     new 3651091037 Fix#9355  Make hop run return exit code 1 when the pipeline 
or workflow fails (#9403)
3651091037 is described below

commit 365109103750a3ff4e815126ff42fdd78409defe
Author: Lance <[email protected]>
AuthorDate: Wed Nov 11 17:10:42 2026 +0800

    Fix#9355  Make hop run return exit code 1 when the pipeline or workflow 
fails (#9403)
    
    * Fix Make hop run return exit code 1 when the pipeline or workflow fails
    
    Signed-off-by: leehaut <[email protected]>
    
    * Fix Make hop run return exit code 1 when the pipeline or workflow fails
    
    Signed-off-by: leehaut <[email protected]>
    
    ---------
    
    Signed-off-by: leehaut <[email protected]>
---
 .../java/org/apache/hop/run/HopCommandRun.java     |  10 +-
 .../apache/hop/run/HopCommandRunExitCodeTest.java  |  56 ++++++++++
 integration-tests/hop_run/0004-abort.hpl           | 102 +++++++++++++++++
 integration-tests/hop_run/0004-pass.hpl            |  98 ++++++++++++++++
 integration-tests/hop_run/hop-run-exit-code.sh     |  62 +++++++++++
 .../hop_run/main-0004-hop-run-exit-code.hwf        | 124 +++++++++++++++++++++
 6 files changed, 449 insertions(+), 3 deletions(-)

diff --git a/engine/src/main/java/org/apache/hop/run/HopCommandRun.java 
b/engine/src/main/java/org/apache/hop/run/HopCommandRun.java
index be1543d674..5ee1cdc47f 100644
--- a/engine/src/main/java/org/apache/hop/run/HopCommandRun.java
+++ b/engine/src/main/java/org/apache/hop/run/HopCommandRun.java
@@ -18,6 +18,7 @@
 
 package org.apache.hop.run;
 
+import java.util.concurrent.Callable;
 import lombok.Getter;
 import lombok.Setter;
 import org.apache.hop.core.Const;
@@ -37,7 +38,7 @@ import picocli.CommandLine.Command;
 @Command(mixinStandardHelpOptions = true, description = "Run a pipeline or 
workflow")
 @HopCommand(id = "run", description = "Runs a pipeline or workflow")
 public class HopCommandRun extends HopRunBase
-    implements Runnable, IHasHopMetadataProvider, IHopCommand {
+    implements Callable<Integer>, IHasHopMetadataProvider, IHopCommand {
 
   public HopCommandRun() {
     super();
@@ -54,9 +55,12 @@ public class HopCommandRun extends HopRunBase
     Hop.addMixinPlugins(cmd, ConfigPlugin.CATEGORY_RUN);
   }
 
+  // Callable so picocli (hop.cmd.execute) gets the exit code; Runnable always 
exits 0.
+  // Same contract as HopRun.main: 0 = ok, 1 = pipeline/workflow failed.
   @Override
-  public void run() {
+  public Integer call() {
     System.setProperty(Const.HOP_PLATFORM_RUNTIME, "RUN");
-    super.run();
+    run();
+    return isFinishedWithoutError() ? 0 : 1;
   }
 }
diff --git 
a/engine/src/test/java/org/apache/hop/run/HopCommandRunExitCodeTest.java 
b/engine/src/test/java/org/apache/hop/run/HopCommandRunExitCodeTest.java
new file mode 100644
index 0000000000..ed42ce05ec
--- /dev/null
+++ b/engine/src/test/java/org/apache/hop/run/HopCommandRunExitCodeTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.run;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+/**
+ * {@code hop run} must surface pipeline/workflow failure as a non-zero 
process exit code (#9355). A
+ * {@link Runnable} command always exits 0 under picocli; {@link 
java.util.concurrent.Callable}
+ * returns the code.
+ */
+class HopCommandRunExitCodeTest {
+
+  @Test
+  void callReturnsZeroWhenRunSucceeded() {
+    assertEquals(0, commandThatFinishes(true).call());
+  }
+
+  @Test
+  void callReturnsOneWhenRunFailed() {
+    assertEquals(1, commandThatFinishes(false).call());
+  }
+
+  @Test
+  void picocliExecuteUsesCallReturnValue() {
+    assertEquals(1, new CommandLine(commandThatFinishes(false)).execute());
+    assertEquals(0, new CommandLine(commandThatFinishes(true)).execute());
+  }
+
+  private static HopCommandRun commandThatFinishes(boolean withoutError) {
+    return new HopCommandRun() {
+      @Override
+      public void run() {
+        setFinishedWithoutError(withoutError);
+      }
+    };
+  }
+}
diff --git a/integration-tests/hop_run/0004-abort.hpl 
b/integration-tests/hop_run/0004-abort.hpl
new file mode 100644
index 0000000000..f86425429f
--- /dev/null
+++ b/integration-tests/hop_run/0004-abort.hpl
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-->
+<pipeline>
+  <info>
+    <name>0004-abort</name>
+    <name_sync_with_filename>Y</name_sync_with_filename>
+    <description>One row, then Abort with an error, so the pipeline fails 
(issue #9355).</description>
+    <extended_description/>
+    <pipeline_version/>
+    <pipeline_type>Normal</pipeline_type>
+    <parameters>
+    </parameters>
+    <capture_transform_performance>N</capture_transform_performance>
+    
<transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
+    
<transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
+    <created_user>-</created_user>
+    <created_date>2026/11/11 08:00:00.000</created_date>
+    <modified_user>-</modified_user>
+    <modified_date>2026/11/11 08:00:00.000</modified_date>
+  </info>
+  <notepads>
+  </notepads>
+  <order>
+    <hop>
+      <from>Generate rows</from>
+      <to>Abort</to>
+      <enabled>Y</enabled>
+    </hop>
+  </order>
+  <transform>
+    <name>Generate rows</name>
+    <type>RowGenerator</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <fields>
+      <field>
+        <length>-1</length>
+        <name>value</name>
+        <precision>-1</precision>
+        <set_empty_string>N</set_empty_string>
+        <type>String</type>
+      </field>
+    </fields>
+    <interval_in_ms>5000</interval_in_ms>
+    <last_time_field>FiveSecondsAgo</last_time_field>
+    <limit>1</limit>
+    <never_ending>N</never_ending>
+    <row_time_field>now</row_time_field>
+    <attributes/>
+    <GUI>
+      <xloc>128</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>Abort</name>
+    <type>Abort</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <abort_option>ABORT_WITH_ERROR</abort_option>
+    <always_log_rows>Y</always_log_rows>
+    <message>Aborting the pipeline on purpose so hop run must exit 1</message>
+    <row_threshold>0</row_threshold>
+    <attributes/>
+    <GUI>
+      <xloc>320</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform_error_handling>
+  </transform_error_handling>
+  <attributes/>
+</pipeline>
diff --git a/integration-tests/hop_run/0004-pass.hpl 
b/integration-tests/hop_run/0004-pass.hpl
new file mode 100644
index 0000000000..5335925c00
--- /dev/null
+++ b/integration-tests/hop_run/0004-pass.hpl
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-->
+<pipeline>
+  <info>
+    <name>0004-pass</name>
+    <name_sync_with_filename>Y</name_sync_with_filename>
+    <description>One row through a Dummy transform, so the pipeline finishes 
(issue #9355).</description>
+    <extended_description/>
+    <pipeline_version/>
+    <pipeline_type>Normal</pipeline_type>
+    <parameters>
+    </parameters>
+    <capture_transform_performance>N</capture_transform_performance>
+    
<transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
+    
<transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
+    <created_user>-</created_user>
+    <created_date>2026/11/11 08:00:00.000</created_date>
+    <modified_user>-</modified_user>
+    <modified_date>2026/11/11 08:00:00.000</modified_date>
+  </info>
+  <notepads>
+  </notepads>
+  <order>
+    <hop>
+      <from>Generate rows</from>
+      <to>Dummy</to>
+      <enabled>Y</enabled>
+    </hop>
+  </order>
+  <transform>
+    <name>Generate rows</name>
+    <type>RowGenerator</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <fields>
+      <field>
+        <length>-1</length>
+        <name>value</name>
+        <precision>-1</precision>
+        <set_empty_string>N</set_empty_string>
+        <type>String</type>
+      </field>
+    </fields>
+    <interval_in_ms>5000</interval_in_ms>
+    <last_time_field>FiveSecondsAgo</last_time_field>
+    <limit>1</limit>
+    <never_ending>N</never_ending>
+    <row_time_field>now</row_time_field>
+    <attributes/>
+    <GUI>
+      <xloc>128</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform>
+    <name>Dummy</name>
+    <type>Dummy</type>
+    <description/>
+    <distribute>Y</distribute>
+    <custom_distribution/>
+    <copies>1</copies>
+    <partitioning>
+      <method>none</method>
+      <schema_name/>
+    </partitioning>
+    <attributes/>
+    <GUI>
+      <xloc>320</xloc>
+      <yloc>96</yloc>
+    </GUI>
+  </transform>
+  <transform_error_handling>
+  </transform_error_handling>
+  <attributes/>
+</pipeline>
diff --git a/integration-tests/hop_run/hop-run-exit-code.sh 
b/integration-tests/hop_run/hop-run-exit-code.sh
new file mode 100755
index 0000000000..9babb58e11
--- /dev/null
+++ b/integration-tests/hop_run/hop-run-exit-code.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+
+# Runs the hop launcher (hop → Hop.main → System.exit) on a pipeline that 
aborts with an error
+# and expects exit code 1, then on a pipeline that finishes and expects 0 
(issue #9355).
+# hop-run.sh already returns that code from HopRun.main; this checks the hop 
run command.
+
+set -u
+
+# The integration-test image only marks *.sh executable. hop sits next to 
hop-run.sh.
+HOP="$(dirname "$(command -v hop-run.sh)")/hop"
+
+fail() {
+  echo "FAILED: ${1}"
+  if [ -n "${LOG:-}" ] && [ -f "${LOG}" ]; then
+    echo "----- output -----"
+    cat "${LOG}"
+  fi
+  exit 1
+}
+
+# <file> <expected exit code>
+run_hop() {
+  local file="${1}"
+  local expected="${2}"
+  LOG="$(mktemp)"
+  echo "hop run -r local -f ${file}, expecting exit code ${expected}"
+  if [ -x "${HOP}" ]; then
+    "${HOP}" run -e dev -r local -l Basic -f "${PROJECT_HOME}/${file}" 
>"${LOG}" 2>&1
+  else
+    bash "${HOP}" run -e dev -r local -l Basic -f "${PROJECT_HOME}/${file}" 
>"${LOG}" 2>&1
+  fi
+  local code=$?
+  if [ "${code}" -ne "${expected}" ]; then
+    fail "hop run ${file} exited ${code}, expected ${expected}"
+  fi
+  rm -f "${LOG}"
+}
+
+[ -f "${HOP}" ] || fail "hop launcher not found next to hop-run.sh"
+
+run_hop "0004-abort.hpl" 1
+run_hop "0004-pass.hpl" 0
+
+echo "hop run exit code is 1 for the aborting pipeline and 0 for the passing 
pipeline"
diff --git a/integration-tests/hop_run/main-0004-hop-run-exit-code.hwf 
b/integration-tests/hop_run/main-0004-hop-run-exit-code.hwf
new file mode 100644
index 0000000000..3077e9212d
--- /dev/null
+++ b/integration-tests/hop_run/main-0004-hop-run-exit-code.hwf
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-->
+<workflow>
+  <name>main-0004-hop-run-exit-code</name>
+  <name_sync_with_filename>Y</name_sync_with_filename>
+  <description>hop run exits 1 when a pipeline aborts with an error and 0 when 
it finishes (issue #9355).</description>
+  <extended_description/>
+  <workflow_version/>
+  <created_user>-</created_user>
+  <created_date>2026/11/11 08:00:00.000</created_date>
+  <modified_user>-</modified_user>
+  <modified_date>2026/11/11 08:00:00.000</modified_date>
+  <parameters>
+  </parameters>
+  <actions>
+    <action>
+      <name>Start</name>
+      <description/>
+      <type>SPECIAL</type>
+      <attributes/>
+      <DayOfMonth>1</DayOfMonth>
+      <doNotWaitOnFirstExecution>N</doNotWaitOnFirstExecution>
+      <hour>12</hour>
+      <intervalMinutes>60</intervalMinutes>
+      <intervalSeconds>0</intervalSeconds>
+      <minutes>0</minutes>
+      <repeat>N</repeat>
+      <schedulerType>0</schedulerType>
+      <weekDay>1</weekDay>
+      <parallel>N</parallel>
+      <xloc>64</xloc>
+      <yloc>96</yloc>
+      <attributes_hac/>
+    </action>
+    <action>
+      <name>Check exit code</name>
+      <description>Runs hop run on 0004-abort.hpl and expects exit code 1, 
then on 0004-pass.hpl and expects 0. The script logs why it 
failed.</description>
+      <type>SHELL</type>
+      <attributes/>
+      <filename>${PROJECT_HOME}/hop-run-exit-code.sh</filename>
+      <work_directory>${PROJECT_HOME}</work_directory>
+      <arg_from_previous>N</arg_from_previous>
+      <exec_per_row>N</exec_per_row>
+      <set_logfile>N</set_logfile>
+      <logfile/>
+      <set_append_logfile>N</set_append_logfile>
+      <logext/>
+      <add_date>N</add_date>
+      <add_time>N</add_time>
+      <insertScript>N</insertScript>
+      <script/>
+      <loglevel>Basic</loglevel>
+      <parallel>N</parallel>
+      <xloc>288</xloc>
+      <yloc>96</yloc>
+      <attributes_hac/>
+    </action>
+    <action>
+      <name>Success</name>
+      <description/>
+      <type>SUCCESS</type>
+      <attributes/>
+      <parallel>N</parallel>
+      <xloc>512</xloc>
+      <yloc>96</yloc>
+      <attributes_hac/>
+    </action>
+    <action>
+      <name>Abort</name>
+      <description/>
+      <type>ABORT</type>
+      <attributes/>
+      <always_log_rows>N</always_log_rows>
+      <message>hop run did not return the expected exit code, see the output 
of the script above</message>
+      <parallel>N</parallel>
+      <xloc>288</xloc>
+      <yloc>240</yloc>
+      <attributes_hac/>
+    </action>
+  </actions>
+  <hops>
+    <hop>
+      <from>Start</from>
+      <to>Check exit code</to>
+      <enabled>Y</enabled>
+      <evaluation>Y</evaluation>
+      <unconditional>Y</unconditional>
+    </hop>
+    <hop>
+      <from>Check exit code</from>
+      <to>Success</to>
+      <enabled>Y</enabled>
+      <evaluation>Y</evaluation>
+      <unconditional>N</unconditional>
+    </hop>
+    <hop>
+      <from>Check exit code</from>
+      <to>Abort</to>
+      <enabled>Y</enabled>
+      <evaluation>N</evaluation>
+      <unconditional>N</unconditional>
+    </hop>
+  </hops>
+  <notepads>
+  </notepads>
+  <attributes/>
+</workflow>

Reply via email to