1

My deploy script is an extremely simple Git pull. I have a bash script that does git pull that’s part of my source code. The issue is that if the git pull fails for any reason, it’s still showing a successful deployment.

The .gitlab-ci.yml:

stages:
    - 'deploy'
deploy to staging:
    stage: 'deploy'
    script: '/home/myuser/scripts/deployment/deploy_staging.sh'
    tags:
        - staging
    only:
        - staging

The deploy_staging.sh:

script=$(basename $0)

logger "$script: script executed"
cd $HOME/mydirectory
git fetch
git pull
composer update

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.