I have an AWS with two instances. I have configured CodeDeploy to deploy my project automatically on all instances.
In the appspec.yml
I have that section:
hooks:
AfterInstall:
- location: codedeploy_scripts/deploy_afterinstall
timeout: 300
runas: root
deploy_afterinstall
is a simple bash script. Sometimes some of commands in it fail. For example this command which updates/installs composer dependencies.
if [ -f "composer.lock" ]; then
composer update -n
else
composer install -n
fi
But CodeDeploy ignores any errors in this script and always says that deployment went successfully. How can I change this behaviour? I want deployment to fail when some of the commands in the hook haven't been finished successfully and to see the errors in the deployment console or log.
If an event hook is not present, no operation is executed for that event. This section is required only if you are running scripts or Lambda validation functions as part of the deployment.
Here's the steps I would take: Confirm that you installed the CodeDeploy agent. Confirm that you've created the IAM service role. Confirm that you have the IAM Instance Profile and that it's associated with the instance.
CodeDeploy rolls back deployments by redeploying a previously deployed revision of an application as a new deployment. These rolled-back deployments are technically new deployments, with new deployment IDs, rather than restored versions of a previous deployment. Deployments can be rolled back automatically or manually.
The application specification file (AppSpec file) is a YAML -formatted or JSON-formatted file used by CodeDeploy to manage a deployment. The AppSpec file for an EC2/On-Premises deployment must be named appspec. yml or appspec. yaml , unless you are performing a local deployment.
I ran into similar problems with CodeDeploy initially. I would recommend making your bash scripts more strict:
#!/bin/bash
set -euo pipefail
By setting e, u, and o pipefail as options Bash will behave more like a programming language and less like a script. You can read more about "Bash Strict Mode" here.
When your composer install or update fails, Bash will then exit with a non-zero code and the code deployment will fail.
CodeDeploy agent relies on exit status of your script 'deploy_afterinstall' to determine whether to succeed or fail the deployment lifecycle event. You might want to see if you can capture the exit status of the command you run in your script and return it from 'deploy_afterinstall'. Any non zero return value from your script should fail the deployment lifecycle event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With