aws / aws-codedeploy-agent

Host Agent for AWS CodeDeploy
https://aws.amazon.com/codedeploy
Apache License 2.0
329 stars 187 forks source link

Empty hook causing deployment failure #125

Closed edward2a closed 7 years ago

edward2a commented 7 years ago

Hi, just run across this issue when testing a templated appspec.yml.

Apparently there is a for-each loop parsing the deployment hooks and when a hook is empty (say, it is there for reference), it fails with: Error CodeUnknownError Message undefined method `each' for nil:NilClass

I assume there is no validation of 'hook is nil' or 'hook is array' and yaml syntax validation is not likely to alert on this as 'mykey: ' is valid (please correct me here if I'm wrong here).

You could argue that non-used stuff should not be there, but that will require processing in the template building process to remove null value keys and, personally, I believe it would be easier to validate 'hook is array' before trying to execute it.

Just a thought.

tangerini commented 7 years ago

Can you provide your appspec.yml file?

edward2a commented 7 years ago

The following file:

version: 0.0

os: linux

hooks:

  BeforeInstall:

  AfterInstall:
    - location: scripts/test.sh

files:

  - source: files/test.txt
    destination: /tmp

permissions:

...

Causes the following:

BeforeInstall | July 25, 2017 9:51:22 AM UTC | July 25, 2017 9:51:22 AM UTC | less than one second | Failed | View Logs

Error CodeUnknownError Script Name Message undefined method `each' for nil:NilClass Log Tail

edward2a commented 7 years ago

2017-07-28 08:30:40 ERROR [codedeploy-agent(30701)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: NoMethodError - undefined method `each' for nil:NilClass - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb:58:in `block in parse_hooks'

edward2a commented 7 years ago

https://github.com/aws/aws-codedeploy-agent/pull/127

edward2a commented 7 years ago

https://pics.me.me/hello-from-the-other-side-of-the-screen-com-14249652.png

feverLu commented 7 years ago

Pull request merged.