由于错误“文件已存在”,使用CodeDeploy部署在“安装”步骤失败

时间:2016-08-08 15:10:23

标签: amazon-web-services jenkins deployment aws-code-deploy

这是我在“安装”步骤中遇到的错误 -

File already exists at location /var/cake_1.2.0.6311-beta/app/webroot/../../somefile.php

我无法断定为这种情况带来了什么样的事件。但我记得的是 -

  • 我通过jenkins启动了部署(集成了代码部署插件)。在“安装”步骤中部署失败,上面粘贴了错误。

    注意 - 这是appspec.yml文件的files部分中的第一个文件。

  • 据我所知,我在同一部署组上进行了一些部署,直接通过代码部署(最有可能使用Jenkins在上面步骤中创建的相同S3文件)并且它已经成功。

    • 然后我有几次失败的部署(故意在各个步骤失败,例如在安装之前退出非零数字)。

此后,即使直接通过代码部署,我也无法成功部署。

背景

我检查了显示相关的this question并尝试删除/opt/codedeploy-agent/deployment-root/​中的所有内容,如one of the answers中所述,但是,它导致我的实例中的代码部署已损坏并通过Jenkins部署开始抛出这个错误说来自archive的appspec文件(它试图找到最后一次成功部署,似乎已被删除)未找到 -

Jenkins triggered code deploy is failing at ApplicationStop step even though same deployment group via code deploy directly is running successfully

然后我重新安装了实例上的代码部署,上面提到的步骤就是我之后做的。

更新 - 开放赏金

正如Rodrigo M所回答的那样,从实例上的部署路径中删除这些文件到目前为止对我有用,但是对于这个特定文件同样不起作用 -

 File already exists at location /var/cake_1.2.0.6311-beta/deployment/serverLoad.json

我验证了以下内容 -

  • 在所有实例上从上述位置删除文件后,我进行了新的部署。我发现文件重新出现但仍然抛出了与上面提到的相同的错误并且部署失败。

  • 不删除,我将文件chmod到777.结果相同。

有趣的是,昨天我收到了多个文件的错误,我继续逐个删除它们,因为我发现它们并采用了新的构建。除了这个文件之外,所有其他文件的问题都得到了修复,甚至删除都没有用。我不知道了!

注 - 我现在正在进行的所有部署都是由Jenkins触发的(没有通过AWS代码部署触发直接部署)。

以下是来自/var/log/aws/codedeploy-agent/codedeploy-agent.log的日志跟踪,其中包含相关的错误堆栈 -

2016-11-10 07:38:12 INFO  [codedeploy-agent(16889)]: Version file found in /opt/codedeploy-agent/.version.
2016-11-10 07:38:12 INFO  [codedeploy-agent(16889)]: [Aws::CodeDeployCommand::Client 200 0.025545 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{\"error_code\":5,\"script_name\":\"\",\"message\":\"File already exists at location /var/cake_1.2.0.6311-beta/deployment/serverLoad.json\",\"log\":\"\"}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvUHJvZC9hcm46YXdzOnNkczp1cy1lYXN0LTE6Mzc3NzAzOTYxOTk4OmRlcGxveW1lbnQvZC1VOVFPR0RBWUkiLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6Mzc3NzAzOTYxOTk4Omluc3RhbmNlL2ktZWNmYzU1YTkiLCJjb21tYW5kTmFtZSI6Ikluc3RhbGwiLCJjb21tYW5kUG9zaXRpb24iOjQsImNvbW1hbmRBdHRlbXB0IjoxfV0=")

2016-11-10 07:38:12 ERROR [codedeploy-agent(16889)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: RuntimeError - File already exists at location /var/cake_1.2.0.6311-beta/deployment/serverLoad.json - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:115:in `generate_normal_copy'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:67:in `block (2 levels) in generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:55:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:55:in `block in generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/install_instruction.rb:68:in `generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:54:in `generate_instructions'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/installer.rb:34:in `install'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:114:in `block in <class:CommandExecutor>'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:62:in `execute_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:132:in `process_command'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_poller.rb:65:in `perform'
/opt/codedeploy-agent/lib/instance_agent/agent/base.rb:28:in `run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:38:in `block in run'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:37:in `run'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:70:in `block in run_with_error_handling'
/opt/codedeploy-agent/lib/instance_agent/runner/child.rb:55:in `with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:69:in `run_with_error_handling'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:33:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `loop'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/child.rb:22:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:206:in `block in spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:204:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:204:in `spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:196:in `block in spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:195:in `times'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:195:in `spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:134:in `start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:37:in `block in start'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:36:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:36:in `start'
/opt/codedeploy-agent/bin/../lib/codedeploy-agent.rb:41:in `block (2 levels) in <main>'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/command_support.rb:130:in `execute'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:262:in `block in call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:275:in `call_command'
/opt/codedeploy-agent/vendor/gems/gli-2.5.6/lib/gli/app_support.rb:69:in `run'
/opt/codedeploy-agent/bin/../lib/codedeploy-agent.rb:88:in `<main>'

更新2

我能够通过重命名json文件并删除appspec.yml中的旧文件引用来应用脏修复。但是,在新的部署组(具有新的ec2实例)上,新的json文件导致相同的文件退出问题。每次更改文件名都很痛苦。对发生的事情非常恼火。

2 个答案:

答案 0 :(得分:7)

作为其流程的一部分,CodeDeploy将查找有关应用程序/部署组以前部署的文件的信息。如果那时它使用此信息删除现有文件,并根据需要准备部署新修订。

http://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-steps.html#deployment-rollback

在这种情况下,由于您之前可能已进行过手动清理,因此存在一些不一致的引用。

所有部署的一个好选择是在BeforeInstall挂钩期间简单地删除部署文件夹中的所有文件。这将解决现在和未来的问题。

答案 1 :(得分:0)

这是可以修复的。 Codedeploy会对尚未部署的文件抛出错误。但是有一个选项可以在部署期间解决这个问题。

“内容选项: 选择在部署期间,当目标实例上的文件与应用程序修订中的文件同名时,对于同一目标位置,AWS CodeDeploy将采取的操作。“

您可以选择失败,覆盖和保留。这取决于你的情况。

您可以找到更多信息