Deploy failing with git pull yet still passing


#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 deploy.

In circle CI, my deploy commands are:
deployment:
prod:
branch: master
commands:
- ./deploy-to-production.sh
staging:
branch: staging
commands:
- ./deploy-to-staging.sh

deploy-to-production is a simple script that lets CircleCI ssh and run the pull
#!/usr/bin/env bash
ssh myuser@xxx.myserver.com -i ~/.ssh/mykey.pub -t “cd /home/xxxxx/yyyyy && ./deploy.sh”

The issue is that git pull can fail, but the deploy still shows that it passes. Below is the output (the git conflict caused it to fail) but CircleCI shows green.

./deploy-to-production.sh
Warning: Identity file /home/ubuntu/.ssh/mykey.pub not accessible: No such file or directory.
Warning: Permanently added ‘xxxx.myserver.com,123.123.123.123’ (ECDSA) to the list of known hosts.

Deploying…

remote: Counting objects: 3, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:myaccount/myproject
f23cff8…1793a48 master -> origin/master
Updating f23cff8…1793a48
error: Your local changes to the following files would be overwritten by merge:
mysqlbackup.sh
Please, commit your changes or stash them before you can merge.
Aborting
Running any db migrations.

Yii Migration Tool v1.0 (based on Yii v1.1.8)

No new migration found. Your system is up-to-date.
Deployed.

Connection to xxxxx.server.com closed.


#2

I have a similar issue with a deploy script using fastlane. The archiving step fails and therefore fastlane fails, but CircleCI reports the build as a success. This means builds are failing to be deployed, but I never get notified of the failure. The docs say:

If a command fails during any of the setup sections (machine, checkout, dependencies, database, compile), the entire build will fail early.

Apparently a failure in the deploy section does not cause the build to fail. Is there a way I can propagate the exit code to CircleCI so the build fails on deploy? Do I need to place my deploy code in a different section?


#3

You could try placing the script is test: post. You’d then need to use Bash to make sure it only runs on the branches you want, i.e. master.


#4

Seems like a bit of a hack, but it would work! Thanks for the idea.


#5