...

/

Setting a Failure Exit Code in a Docker Container

Setting a Failure Exit Code in a Docker Container

Set a failure exit code in a Docker container when the workflow fails.

When the workflow failed to get the vault password, the build returned a green checkmark. It did not accurately return the Ansible failure. Without an accurate build status, you won’t know what or when to troubleshoot.

You fix this issue by setting failure exit codes in the Docker container. There are many ways to go about it, but a simple solution is to add an if statement to the entrypoint.sh.

Review the if statement below:

Press + to interact
if ! ansible-playbook -i hosts_azure_rm.yml site.yml --vault-password-file .vault;
then
echo "Ansible failed!"
rm .vault
exit 1
else
rm .vault
fi

The entrypoint.sh now echoes Ansible failed! And throws an exit code of 1 when the ansible-playbook does not exit with a 0. This is enough for the Github workflow to report an accurate build status.

Update the <dynamic-inventory> with the dynamic inventory of the cloud provider of your choice in the entrypoint.sh file.

Open site.yml ...