亚马逊云科技 - 代码部署部署在安装前事件失败,错误"exit: 0 : numeric argument required"



我的appspec文件中有以下内容(yaml已验证) -

version: 0.0
os: linux
files:
  - source: some/source
    destination: some/destination
hooks:
  BeforeInstall:
    - location: beforeInstall.sh
  AfterInstall:
    - location: afterInstall.sh 

我在安装前步骤中间歇性地收到以下错误 -

Error Code ScriptFailed
Script Name beforeInstall.sh
Message Script at specified location: beforeInstall.sh failed with exit code 255
Log Tail
LifecycleEvent - BeforeInstall
Script - beforeInstall.sh
[stderr]/opt/codedeploy-agent/deployment-root/edbe4bd2-3999-4820-b782-42d8aceb18e6/d-4GJ8QS9MG/deployment-archive/beforeInstall.sh: line 1: exit: 0
: numeric argument required

以下是我 beforeInstall.sh 文件的内容——

exit 0

请注意,生成会间歇性地成功。我尝试了以下方法 -

  • 执行 beforeInstall.sh 文件的 dos2unix。运行构建并在一些试验后成功(不是在更改后立即),所以不能说这是原因。

  • 使用新名称将新的 zip 文件上传到 S3(只是为了避免 EC2 实例上可能发生的任何缓存)。

另外,我发现即使构建成功,文件中提到的文件更改也不会在实例中发生 - 未添加要添加的文件,未进行文件修改。但是,某些现有文件的时间戳已修改为今天。奇怪。

更新

以下是/var/log/aws/codedeploy-agent/codedeploy-agent.log的日志轨迹,exit 1在 beforeInstall.sh -

2016-08-01 12:41:01 WARN  [codedeploy-agent(9507)]: InstanceAgent::Plugins::CodeDeployPlugin::HookExecutor: Script at specified location: beforeInstall.sh is not executable.  Trying to make it executable.
2016-08-01 12:41:01 INFO  [codedeploy-agent(9507)]: Version file found in /opt/codedeploy-agent/.version.
2016-08-01 12:41:01 INFO  [codedeploy-agent(9507)]: [Aws::CodeDeployCommand::Client 200 0.087513 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{"error_code":4,"script_name":"beforeInstall.sh","message":"Script at specified location: beforeInstall.sh run as user sandeepan failed with exit code 255","log":"LifecycleEvent - BeforeInstall\nScript - beforeInstall.sh\n[stderr]/opt/codedeploy-agent/deployment-root/c71b93a2-8561-41e2-b90f-d638548e7b4c/d-A36YRE23H/deployment-archive/beforeInstall.sh: line 1: exit: 0\r: numeric argument required\n"}"},host_command_identifier:"WyJjb20uYW1hem9uLmFwb2xsby5kZXBsb3ljb250cm9sLmRvbWFpbi5Ib3N0Q29tbWFuZElkZW50aWZpZXIiLHsiZGVwbG95bWVudElkIjoiQ29kZURlcGxveS91cy1lYXN0LTEvUHJvZC9hcm46YXdzOnNkczp1cy1lYXN0LTE6Mzc3NzAzOTYxOTk4OmRlcGxveW1lbnQvZC1BMzZZUkUyM0giLCJob3N0SWQiOiJhcm46YXdzOmVjMjp1cy1lYXN0LTE6Mzc3NzAzOTYxOTk4Omluc3RhbmNlL2ktZWZmYzU1YWEiLCJjb21tYW5kTmFtZSI6IkFmdGVySW5zdGFsbCIsImNvbW1hbmRQb3NpdGlvbiI6NSwiY29tbWFuZEF0dGVtcHQiOjF9XQ==")
2016-08-01 12:41:01 ERROR [codedeploy-agent(9507)]: InstanceAgent::Plugins::CodeDeployPlugin::CommandPoller: Error during perform: InstanceAgent::Plugins::CodeDeployPlugin::ScriptError - Script at specified location: beforeInstall.sh run as user sandeepan failed with exit code 255 - /opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:153:in `execute_script'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:110:in `block (2 levels) in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:98:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:98:in `block in execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:168:in `create_script_log_file_if_needed'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/hook_executor.rb:96:in `execute'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:133:in `block (3 levels) in map'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:124:in `each'
/opt/codedeploy-agent/lib/instance_agent/plugins/codedeploy/command_executor.rb:124:in `block (2 levels) in map'
/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:202:in `block in spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:200:in `fork'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:200:in `spawn_child'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:192:in `block in spawn_children'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:191:in `times'
/opt/codedeploy-agent/vendor/gems/process_manager-0.0.13/lib/process_manager/master.rb:191: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/codedeploy-agent:37: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/codedeploy-agent:84:in `<main>'

注意 - 只有当我的 shell 脚本包含退出时,我才能重现此错误。

另外,我不确定shebang线(#!/bin/sh)与此有什么关系。我尝试添加它(验证/bin/sh 中有一些东西)- ls -l /bin/sh给出—— lrwxrwxrwx 1 root root 4 Jun 3 22:23 /bin/sh -> bash

使用该更改进行部署会在 beforeInstall 步骤 中出现以下错误 - [stderr]bash: /opt/codedeploy-agent/deployment-root/c71b93a2-8561-41e2-b90f-d638548e7b4c/d-UOGT00Z2H/deployment-archive/beforeInstall.sh: /bin/sh^M: bad interpreter: No such file or directory

我会专注于Windows vs Linux行尾。

您在问题和评论区域中提供了两个不同的错误。这两个消息都直接指向行尾问题:

exit: 0 : numeric argument required
/bin/sh^M: bad interpreter: No such file or directory

您在该错误消息中看到的 ^M 是回车符 CR(回车符,'\r',0x0D,十进制 13)。Linux 使用换行符来指定行尾,但 Windows 使用字符序列 CR + LF。您的文件具有 Windows 行尾,这会混淆 Linux shell,并导致这些错误消息。

在解决此问题之前,所有故障排除方式都将使您失败。

在编辑环境写入带有 Linux 行尾的文件之前,请尝试以下操作:

  1. 在 Linux 盒子上使用 dos2unix 来纠正这两个文件的问题。
  2. 确认这些文件在服务器上手动运行。这很重要。
  3. 将这些文件复制到开发框中。
  4. 使用这些更正的文件创建 CodeDeploy 修订存档。不要在本地编辑这些文件。
  5. 重新部署存档。

我希望 CodeDeploy 能够正常工作。

我花了几天时间追逐行尾和 CodeDeploy 的确切问题。 很难跟踪,尤其是exit: 0 : numeric argument required消息。它相当迟钝,与退出代码或 shebangs 无关。 它的行尾。

似乎是由于脚本本身从消息"脚本在指定位置运行:beforeInstall.sh 以用户身份运行失败,退出代码为 255"。是否可以在没有 CodeDeploy 的情况下单独运行脚本,并确保脚本正常工作?

相关内容

  • 没有找到相关文章

最新更新