You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行gcloud清理策略命令触发AttributeError错误求助

解决gcloud artifacts repositories set-cleanup-policies命令的AttributeError错误

问题根源

你的清理策略JSON文件结构不符合GCP Artifact Registry的规范:mostRecentVersions字段必须嵌套在condition对象下,而非作为顶层字段存在。当CLI解析错误的结构时,会将本应是字典类型的字段误判为字符串,从而触发'str' object has no attribute 'get'的崩溃错误。

修正后的策略文件

将policy.json内容替换为以下符合规范的结构:

{
  "name": "keep-latest-version",
  "action": {"type": "Keep"},
  "condition": {
    "mostRecentVersions": {
      "packageNamePrefixes": ["users"],
      "keepCount": 1
    }
  }
}

执行步骤

  1. 保存修正后的policy.json文件
  2. 重新运行原命令:
    gcloud artifacts repositories set-cleanup-policies my-repo --policy=policy.json
    

可选测试方式

若怀疑文件路径或读取问题,可直接通过命令行传入JSON字符串执行:

gcloud artifacts repositories set-cleanup-policies my-repo --policy='{"name": "keep-latest-version", "action": {"type": "Keep"}, "condition": {"mostRecentVersions": {"packageNamePrefixes": ["users"], "keepCount": 1}}}'

内容的提问来源于stack exchange,提问作者Tom3652

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 13:20:59