【问题标题】:Google cloud build cli - get artifact URL while build is ongoing谷歌云构建 cli - 在构建过程中获取工件 URL
【发布时间】:2023-11-20 08:36:02
【问题描述】:
我正在使用 Google 云构建触发器来构建我的容器映像。推送新构建后(通过 git tag 推送),我可以在我的 Cloud Build 历史记录中看到它。
如您所见,构建已经有一个artifact URI(图像的URI)。但是,当调用 gcloud build list 时 - 它不存在:
它仅在建筑物完成后出现在 IMAGE 列中。
如何在构建时获取artifact 构建?
【问题讨论】:
标签:
google-cloud-platform
gcloud
google-cloud-build
【解决方案1】:
IIUC,构建和工件是不同的东西。
当您提交 gcloud builds 时,您正在创建由构建 ID 标识的构建(作业)。
构建可能会导致创建工件(通常——但不限于——容器图像)。只有在构建结束时才会生成工件,因此在此之前您不会期望这些工件可用。
steps:
- name: "gcr.io/cloud-builders/docker"
args:
- build
- -t
- "gcr.io/your-project/your-image
- .
images:
- "gcr.io/your-project/your-image"
或者:
artifacts:
objects:
location: [STORAGE_LOCATION]
paths:
- [ARTIFACT_PATH]
- [ARTIFACT_PATH]
- ...
因为您在构建规范中指定了图像|工件,所以您可以推断(在创建这些工件之前)它们将在哪里生成,然后您可以直接查询它们。在推送容器镜像的情况下,您可以使用gcloud container images list 查询这些,也许(根据上述)gcloud container image list --repository=gcr.io/your-project
见:
https://cloud.google.com/cloud-build/docs/configuring-builds/store-images-artifacts#artifacts_examples
HTH!