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

GCP Artifact Registry设置清理政策遇JSON文件解析错误求助

问题描述

我参考GCP官方文档创建清理政策JSON文件,按照示例编写了如下内容:

[
  {
    "name": "my-policy",
    "action": {"type": "Delete"},
    "condition": {
      "versionAge": 30d
    }
  }
]

执行gcloud命令时出现报错:

ERROR: gcloud crashed (InvalidUserInputError): Could not read JSON file retention.json: Expecting ',' delimiter: line 6 column 21 (char 104)

我尝试移除"d"、将值改为字符串等操作,问题仍未解决,请求帮助。

解决方案

核心问题是JSON语法不合法:

  • 30d 不是有效的JSON值,JSON中带单位的时长必须以带双引号的字符串形式存在,正确写法应为 "30d"
  • 同时检查JSON文件是否存在其他语法问题,比如引号不配对、遗漏逗号等

修正后的合法JSON示例:

[
  {
    "name": "my-policy",
    "action": {"type": "Delete"},
    "condition": {
      "versionAge": "30d"
    }
  }
]

如果仍有问题,可先通过JSON校验工具验证文件语法完整性,再执行gcloud命令,示例命令如下:

gcloud artifacts repositories set-cleanup-policies REPOSITORY_NAME --location=LOCATION --cleanup-policies=retention.json

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 11:15:28