小编典典

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

jenkins

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

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

我无法断定此方案带来了什么事件。但是我记得是这样的-

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

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

  • 据我所记得,我直接通过代码部署在同一部署组上进行了一些部署(很可能使用了与詹金斯在上述步骤中创建的同一S3文件),该部署已成功完成。

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

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

背景

我检查了这个似乎相关的问题,并通过删除其中的所有内容进行了尝试/opt/codedeploy-agent/deployment-root/​,如其中一个答案中所述,但是,这导致损坏的代码在我的实例中部署,并通过Jenkins部署开始引发此错误,指出存档文件中的appspec文件(试图寻找最后一次成功的部署,但似乎没有被删除)-

Jenkins触发的代码部署在ApplicationStop步骤失败,即使通过代码部署直接进行的相同部署组已成功运行

然后,我将代码重新安装在实例上,上面提到的步骤是我在此之后所做的。

更新-开放赏金

如Rodrigo M的回答,到目前为止,从实例上的部署路径中删除此类文件对我来说一直有效,但对于该特定文件却不起作用-

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

我验证了以下内容-

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

  • 没有删除,我将文件更改为777。结果相同。

有趣的是,昨天我收到多个文件的错误消息,然后在找到它们并采用新版本的过程中将其逐个删除。除此文件外,所有其他文件的问题均已解决,即使删除也不起作用。我没有线索!

注-我现在正在执行的所有部署都是由Jenkins触发的(AWS代码部署不会触发直接部署)。

这是/var/log/aws/codedeploy-agent/codedeploy-agent.log包含相关错误堆栈strace 的日志跟踪-

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文件导致同一文件退出问题。每次更改文件名都是很痛苦的。对发生的事情非常恼火。


阅读 265

收藏
2020-07-25

共1个答案

小编典典

作为其过程的一部分,CodeDeploy将在app/deployment组的先前已部署文件中查找信息。如果这样,它将使用此信息删除现有文件,并根据需要为新修订的部署做准备。

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

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

对于所有部署,一个不错的选择是在BeforeInstall挂接过程中简单地删除部署文件夹中的所有文件。这将立即解决此问题,并将继续解决此问题。

2020-07-25