Gitlab: Make the CI/CD failed when git pull failed in a bash script on server

Solution 1:

This issue lies in the fact that in order for a job to fail it checks the exit code of the command executed in your case

script: '/home/myuser/scripts/deployment/deploy_staging.sh'

The exit code of this command will be the result of 'composer update'

Since the exit code for a script is the exit code of the latest executed command, in your case 'composer update'

Meaning, this job will fail only if the command 'composer update' fails, disregarding the exit codes of the previous commands in your case 'git pull'

To fix this add "set -e" in the beginnig of your script. This will force the script to adapt a proper exit code by exiting the script when a command in the script fails