用例:
将 txt 文件 (old_snapshots.txt) 中的快照列表导出到 S3 存储桶。从 Jenkins,使用 aws cp 命令将文件复制到 Jenkins /tmp/directory
--dry-run did not show any error
但是,当在 Jenkins 中使用 aws delete 命令传递以下 bash 行时,它显示 SUCCESS,同时表示发生了错误并且未删除快照。
## actual deletion
file="/tmp/old_snapshots.txt"
while read delete_data
do
aws ec2 --region eu-west-1 delete-snapshot --snapshot-id $file
echo "Deleting snapshot $delete_data"
done <"$file"
输出
An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation: Value (/tmp/old_snapshots.txt) for parameter snapshotId is invalid. Expected: 'snap-...'.
Deleting snapshot snap-xxxx81xxxxxx7fxxx
An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation: Value (/tmp/old_snapshots.txt) for parameter snapshotId is invalid. Expected: 'snap-...'.
Deleting snapshot snap-xxxacc49xxxxxxc26
An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation: Value (/tmp/old_snapshots.txt) for parameter snapshotId is invalid. Expected: 'snap-...'.
Deleting snapshot snap-04xxxxxxxx3fa3cxxxxxxf4
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
请求:这个错误An error occurred (InvalidParameterValue) when calling the DeleteSnapshot operation
似乎太笼统了?有没有人遇到过似乎问题?此外,我通过在 Jenkins 中手动添加快照 id 进行了手动测试,使用 aws cli 仅删除单个快照,并且效果很好。任何建议将不胜感激。
包括 aws 命令
aws ec2 --region eu-west-1 delete-snapshot --snapshot-id snap-01x1618xxxxxxa51x
Found snapshotid: snap-01x1618xxxxxxa51x in the uploaded file: /tmp/old_snapshots.txt
Now deleting snapshot id snap-01x1618xxxxxxa51x
你需要稍微改变你的脚本。
您的脚本调用
file
变量是常量,但您需要逐行传递文件的内容。所以,在下面替换和
为了其他社区用户的利益,我使用该
--debug
标志发现附加字符'\r'
被添加到snap-#调试输出
解决问题:我传递
tr -d '\r'
给持有该值的变量,以进行对话。示例:
更新的脚本