Search code examples
node.jsamazon-ec2bitbucket-pipelinesaws-code-deploybitbucket-aws-code-deploy

How do I ignore an error in a CodeDeploy hook?


I'm using Bitbucket pipeline to install my Node application to an EC2 linux instance. The AppSpec.yml file at the root of my application defines the deployment. Before I install, I want to stop all Node processes running on the target server. Here's my BeforeInstall hook:

  BeforeInstall:
      - location: deploy/killallnode.sh
        timeout: 30
        runas: root

The command inside the script is:

killall node

The deployment failed and here's what I find in AWS:

LifecycleEvent - BeforeInstall
Script - deploy/killallnode.sh
[stderr]node: no process found

This error is to be expected. How can I suppress this at the command line, or configure the AppSpec hook to ignore this error? Thanks for your advice!

AWS Error Diagnostic

I tried changing my script command to:

killall node 2> /dev/null

This suppressed the error message, but the killall command still returned an error code of 1.

AWS Diagnostic


Solution

  • There is a property which controls this. IgnoreApplicationStopFailures

    Here's how it is implemented in yaml:

    version: 0.0
    os: linux
    IgnoreApplicationStopFailures: true
    files:
      - source: /
        destination: /api
    hooks:
       ...etc...