Allen.Han
Allen.Han

Reputation: 17

AWS CodePipeline + CodeDeploy + CodeCommit with --file-exists-behavior option

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

Upvotes: 0

Views: 1023

Answers (1)

Kush Vyas
Kush Vyas

Reputation: 6079

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

Upvotes: 1

Related Questions