如何识别cloudbuild子任务

How to identify cloudbuild child tasks

我有一个 CloudBuild cloudbuild.yaml 文件,它定义了一个以 .vmdk 格式将 GCE 图像导出到存储桶的任务。

    gcloud compute images export \
    --image=$IMAGE_NAME \
    --destination-uri=$DESTINATION_BUCKET/$VMDK_NAME \
    --export-format=vmdk \
    --network=$NETWORK \
    --subnet=$SUBNET \
    --project=$PROJECT_ID \
    --async

gcloud compute images export 工作正常;该命令触发子 CloudBuild 转换并上传到 gcs。

新版本中没有标识“父”调用者的字段,这些字段为空: ProviderSourceRef CommitTrigger IdTrigger TypeTrigger NameTrigger Description

如何识别这些子进程?

有趣的问题。

我认为您可能无法执行此操作(请参阅下面的 Hack),因为没有可以从父 Cloud Build 任务通过 gcloud compute images export ... 传递到子 Cloud Build 任务的用户可定义元数据。

Hack I've not tried this! It may (!?) be possible to inject a trace token from Cloud Build into the step that invokes gcloud compute images export command using the --trace-token flag. You could try (I've not tried this) setting this flag on gcloud compute images export ... --trace-token=${SOMETHING} perhaps using the value of the parent's Cloud Build ID? This should be passed through subsequent API calls and hopefully at least reaches as far the child Cloud Build.

我认为能够通过 Cloud SDK 命令传递任意元数据(标签?)是一个有用的功能请求。您应该考虑向 Google 的 Issue Tracker for Cloud SDK

提交请求