AWS CodeDeploy报错:no implicit conversion of String into Integer求助
AWS CodeDeploy错误排查:no implicit conversion of String into Integer
错误信息
[Aws::CodeDeployCommand::Client 200 0.023162 0 retries] put_host_command_complete(command_status:"Failed",diagnostics:{format:"JSON",payload:"{"error_code":5,"script_name":"","message":"no implicit conversion of String into Integer","log":""}"},host_command_identifier:"
相关配置文件
appspec.yml
version: 0.0 os: linux files: source: / destination: /home/ubuntu/build overwrite: yes file_exists_behavior: OVERWRITE permissions: - object: /home/ubuntu pattern: '**' owner: ubuntu group: ubuntu hooks: BeforeInstall: - location: scripts/before-install.sh timeout: 300 runas: root AfterInstall: - location: scripts/after-deploy.sh timeout: 300 runas: root
before-install.sh脚本
#!/bin/bash # 要解压的目录路径 DESTINATION_DIR="/home/ubuntu/build" # 压缩文件路径 ZIP_FILE_PATH="$DESTINATION_DIR/build.zip" # 解压 unzip -q "$ZIP_FILE_PATH" -d "$DESTINATION_DIR" unzip_exit_code=$? if [ $unzip_exit_code -ne 0 ]; then echo "Error: 解压过程中发生错误。退出代码: $unzip_exit_code" exit $unzip_exit_code else echo "解压已成功完成。" fi # 删除压缩文件 rm "$ZIP_FILE_PATH" rm_exit_code=$? if [ $rm_exit_code -ne 0 ]; then echo "Error: 删除压缩文件过程中发生错误。退出代码: $rm_exit_code" exit $rm_exit_code else echo "压缩文件已成功删除。" fi
问题分析与解决方案
核心原因
错误no implicit conversion of String into Integer是CodeDeploy Agent(Ruby编写)的类型转换错误,根源是appspec.yml的files字段格式不符合要求:CodeDeploy要求files是数组结构,每个文件映射需用-标记为数组元素,当前配置将files写成了单个对象,导致Agent解析时类型不匹配。
修复步骤
- 修正appspec.yml的files格式
将files改为数组结构,调整后配置如下:
version: 0.0 os: linux files: - source: / destination: /home/ubuntu/build overwrite: yes file_exists_behavior: OVERWRITE permissions: - object: /home/ubuntu pattern: '**' owner: ubuntu group: ubuntu hooks: BeforeInstall: - location: scripts/before-install.sh timeout: 300 runas: root AfterInstall: - location: scripts/after-deploy.sh timeout: 300 runas: root
- 验证脚本执行(可选)
在before-install.sh开头添加调试日志,确认文件路径有效性:
echo "当前工作目录: $(pwd)" echo "目标目录: $DESTINATION_DIR" echo "压缩文件路径: $ZIP_FILE_PATH"
- 重启CodeDeploy Agent
确保配置修改生效,执行命令:
sudo service codedeploy-agent restart
内容的提问来源于stack exchange,提问作者성찬홍
相关产品推荐
相关产品推荐

