From 4b70e906a0b7ed6ac78f9cf03478fd8b31a96e56 Mon Sep 17 00:00:00 2001 From: andrii-codefresh Date: Tue, 3 Nov 2026 23:05:26 +0200 Subject: [PATCH] fix(codefresh-run): terminate the child build only on timeout With TERMINATE_ON_TIMEOUT=true the step terminated the child build on any `codefresh wait` failure, including temporary API errors (e.g. 520), so healthy child builds were killed. Now the build is terminated only when the timeout is reached. The timeout is detected by exit code 124 (CLI >= 1.3.0) or by the "Operation has timed out" message, so the default CLI image keeps working. Fixes CF-2404 --- graduated/codefresh-run/step.yaml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/graduated/codefresh-run/step.yaml b/graduated/codefresh-run/step.yaml index 917885e97..9b2f343ae 100644 --- a/graduated/codefresh-run/step.yaml +++ b/graduated/codefresh-run/step.yaml @@ -3,7 +3,7 @@ kind: step-type metadata: name: codefresh-run title: Run a Codefresh pipeline - version: 1.6.0 + version: 1.6.1 isPublic: true description: Run a Codefresh pipeline by ID or name and attach the created build logs. sources: @@ -160,7 +160,7 @@ spec: }, "TERMINATE_ON_TIMEOUT": { "type": "boolean", - "description": "Terminate build if timeout reached", + "description": "Terminate build if timeout reached. Other errors (e.g. failed API requests) do not terminate the build", "default": false }, "ONLY": { @@ -262,11 +262,23 @@ spec: - echo "Retrieving logs for build $BUILD_ID" - codefresh logs -f --no-timestamps $BUILD_ID [[- end ]] + [[- if eq .Arguments.TERMINATE_ON_TIMEOUT false ]] - >- codefresh wait --verbose $BUILD_ID --timeout [[(printf "%s" .Arguments.TIMEOUT_MINS)]] - [[- if eq .Arguments.TERMINATE_ON_TIMEOUT true ]] - || (echo "TERMINATE_ON_TIMEOUT was set to true, sending termination request" && - codefresh terminate $BUILD_ID && - exit 1) + [[- else ]] + [[/* Terminate the child build only when the timeout is reached, not on other errors (e.g. API errors). */]] + [[/* The timeout is detected by exit code 124 (CLI >= 1.3.0) or by the error message (older CLI versions exit with 1). */]] + - >- + { codefresh wait --verbose $BUILD_ID --timeout [[(printf "%s" .Arguments.TIMEOUT_MINS)]] 2>&1; + echo $? > /tmp/codefresh-wait.rc; } | tee /tmp/codefresh-wait.log; + WAIT_RC=$(cat /tmp/codefresh-wait.rc 2>/dev/null); + if [ "$WAIT_RC" != "0" ]; then + WAIT_RC=${WAIT_RC:-1}; + if [ "$WAIT_RC" -eq 124 ] || grep -q "Operation has timed out" /tmp/codefresh-wait.log; then + echo "TERMINATE_ON_TIMEOUT was set to true, sending termination request"; + codefresh terminate $BUILD_ID; + fi; + exit $WAIT_RC; + fi [[- end ]] [[- end -]]