cloudbuil.yaml 在构建触发器上使用 base64 编码值时不解组

cloudbuil.yaml does not unmarshall when using base64-encoded value on build trigger

在我的 cloudbuild.yaml 定义中,我曾经有一个 secrets 部分来从 Google KMS 获取环境值。 secretEnv 字段具有映射到 'encrypted + base64-encoded' 值的键:

...

secrets:
- kmsKeyName: <API_PATH>
  secretEnv:
    <KEY>: <ENCRYPTED+BASE64>

我尝试将此值放在替换上,当使用构建触发器时替换:

...

secrets:
- kmsKeyName: <API_PATH>
  secretEnv:
    <KEY>: ${_VALUE}

因此我打算保持文件的通用性。

但是,构建过程不断失败并显示消息解组构建配置失败cloudbuild.yaml:输入字节 0 处的 base64 数据非法。我已经检查了好几次,base64 值没有被错误地复制到触发器的替换中。

提前致谢。

https://cloud.google.com/cloud-build/docs/configuring-builds/substitute-variable-values

仔细阅读 Using user-defined substitutions 部分后,我看到了

The length of a parameter key is limited to 100 bytes and the length of a parameter value is limited to 4000 bytes.

我的是一个 253 个字符的长字符串。

我设法重现了与您的错误类似的错误(正是这个错误:"Failed to trigger build: failed unmarshalling build config cloudbuild.yaml: json: cannot unmarshal string into Go value of type map[string]json.RawMessage, it is because using")。但这仅在我的变量类似于“name:content”而不是“name:content”时才发生。 注意白色 space,非常重要。

然后,回到你的观点...用户定义的替换被限制在 255 个字符以内(是的,文档当前是错误的,并且已经报告过)。但是,例如,如果您使用类似的东西:

substitutions:
    variable_name: cool_really_long_content_but_still_no_255_chars

然后你这样做:

steps:
- name: "gcr.io/cloud-builders/docker"
  args: ["build", "-t", "gcr.io/$PROJECT_ID/$cool_really_long_content_but_still_no_255_chars", "."]

如果 "gcr.io/$PROJECT_ID/$cool_really_long_content_but_still_no_255_chars" 实际上超过 255 个字符,即使您的真正长内容仍然不是 255 个字符,它仍然会失败。并且此错误将出现在构建详细信息>日志中,而不是当您在 Google Cloud Build 的 "build triggers" 部分中单击 "run trigger" 时看到的弹出窗口,这是报告错误的类型出现是因为这种情况下的日志在构建详细信息部分中显示为禁用。