Gitlab Job Exits with Status 1 on given timeout

Replace this template with your information


Hello, I have an issue with Deploy job that exits with status 1.
We’re deploying to Kubernetes using Helm and Gitlab.
On Deploy Stage, we want to see the status of K8S Deployment, therefore , we run this command -

timeout 600 kubectl rollout status --watch “{DEPLOYMENT_RESOURCE}"/"{DEPLOYMENT_NAME%-}” --namespace="${K8S_NAMESPACE}"

Basically we’re watching the deployment status, and if it’s not been deployed within 600 secs, there’s timeout.
After the timeout, I want to print the K8S events, or to print any kind of message, but I can’t. Because of the timeout, GitLab job exits with status 1, so the job failed. And I can’t provide any additional commands.
Here is part of logic -

Give the helm deployment 15 minutes to be successfull, otherwise fail the job

    DEPLOYMENT_RESOURCE=${DEPLOYMENT_RESOURCE:-deployment} # can be deployments/statefulsets/daemonsets/jobs
    if [[ ${CHECK_DEPLOYMENT} == "TRUE" ]]; then
        timeout 900 kubectl rollout status --watch "${DEPLOYMENT_RESOURCE}"/"${DEPLOYMENT_NAME%-}" --namespace="${K8S_NAMESPACE}"
        if [[ $? == 124 ]]; then echo "Deployment of ${RELEASE_NAME} failed" && exit 1; fi

The if statement after the timout command , does not work from the reason I wote above.
Is there any kind of workaround for such case?
I uploaded a screenshot with the Job failed status


You can handle the exit status from timeout and then check for it later in order to pass the exit status you want to the GitLab runner. E.g.:

timeout 1 sleep 2 || TIMED_OUT=true
if [[ -n "$TIMED_OUT" ]]; then 
    echo do some stuff
    # ...
    exit 1