GitLab unable to read the exit code of shell script

I am using a script (.sh script) in my GitLab CI/CD script.

The problem I am facing is that even if the script fails for some reason, GitLab says that the stage has passed successfully. The script basically is a make command, and if the make command fails, GitLab is unable to understand that it has failed, and it continues with the remaining steps of the pipeline.

I tried storing the exit command of the script in a variable, and then checking if the variable is a 1 or 0 at the end. But this does not seem to work.

I have attached the stage where this failure occurs:

stageTwo:
  stage: x86_build
  script:
        - export CDHOME=/home/gitlab-runner/builds/runner_id/0/organization
        # - export COMMIT_TS = $CI_COMMIT_TIMESTAMP
        - cd /home/gitlab-runner/builds/runner_id/0/organization/source_dir/devops/ 
        - docker images
        - docker rmi -f $(docker images -q)
         # This is where script execution starts
        - ./build_docker.sh x86 build $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA && RET1=$?
        - docker images
        - if [ $RET1 != 0 ]; then exit 2; fi

I would really appreciate any help in solving this issue. If unattended, this could potentially affect the deployment