0

I have a CD work flow using CodePipeline + CodeCommit + CodeDeploy to EC2 instances.

I have everything else working except for this --file-exists-behavior option. If I create a deployment from the Aws CLI or the console. The deployment works fine.

Is there anyway I can use this option with CodePipeline?

I am still getting an error without this option.

The deployment failed because a specified file already exists at this location

Allen.Han
  • 17
  • 6
  • Similar solution discussed: https://stackoverflow.com/questions/41590332/aws-codedeploy-fail-the-deployment-failed-because-a-specified-file-already-exis – Kannaiyan Oct 05 '17 at 02:27
  • Hi, Kannaiyan, i ve read that question, but it doesnt involve codePipeline. – Allen.Han Oct 05 '17 at 03:03

1 Answers1

1

So, when you deploy, CodeDeploy will look for a file (on the instance) with information on previously deployed files for the application/deployment-group in question, if it finds the file it then it uses it to cleanup (delete) the existing files, preparing for copying of the new revision files.

Refer This AWS Documentation

But if the cleanup file doesn't exist, either because the existing code was initially deployed in some other way (eg cloudformation instance userdata/metadata sources) or the CodeDeploy deployment-group has been recreated for some reason then the cleanup file will either not exist or not match the deployment-group id. Therefore it wont be run. Therefore the files will not be cleaned up, and the deployment will fail since CodeDeploy does not overwrite files.

What a Solution could be in this scenario is to have a hook (eg BeforeInstall) that calls a script to delete the applications files (if they exist) on the instance.

Hope this helps

Kush Vyas
  • 5,813
  • 2
  • 26
  • 36
  • Does it mean, if I deploy the files once with CLI or console once, I dont have to worry about --file-exists-behavior option? – Allen.Han Oct 05 '17 at 21:19
  • Nope that was for CLI you would still need an script for before install to remove existing file – Kush Vyas Oct 11 '17 at 13:03