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 -]]