[英]GCP: Cloud Run preview build fails because of a missing tag "latest"
[英]Cloud Build API call to check information regarding the latest build
我一直在使用 Cloud Build API 以從 Google Cloud Build 獲取最新的圖像信息,該信息將我們的 Google Cloud Kubernetes 部署圖像構建到我們的 Django 后端應用程序中以觸發新的 Job/Pod。
下面是收集信息的代碼。
from google.cloud.devtools import cloudbuild_v1
def sample_list_builds():
# Create a client
client = cloudbuild_v1.CloudBuildClient()
# Initialize request argument(s)
request = cloudbuild_v1.ListBuildsRequest(
project_id="project_id_value",
)
# Make the request
page_result = client.list_builds(request=request)
# Handle the response
for response in page_result:
print(response)
我只想在找到第一個成功構建時退出循環,但是我找不到如何與 Status.Success 進行比較。 它似乎不是一個字符串。 我拿什么來比較這個?
images: "eu.gcr.io/.../.../...-dev:f2529...0ac00402"
project_id: "..."
logs_bucket: "gs://106...1.cloudbuild-logs.googleusercontent.com"
source_provenance {
}
build_trigger_id: "...-d5fd-47b7-8949-..."
options {
substitution_option: ALLOW_LOOSE
logging: LEGACY
dynamic_substitutions: true
pool {
}
}
log_url: "https://console.cloud.google.com/cloud-build/builds/...-1106-44d5-a634-...?project=..."
substitutions {
key: "BRANCH_NAME"
value: "staging"
}
substitutions {
key: "COMMIT_SHA"
value: "..."
}
substitutions {
key: "REF_NAME"
value: "staging"
}
substitutions {
key: "REPO_NAME"
value: "videoo-app"
}
substitutions {
key: "REVISION_ID"
value: "....aa3f5276deda3c10ac00402"
}
substitutions {
key: "SHORT_SHA"
value: "f2529c2"
}
substitutions {
key: "TRIGGER_BUILD_CONFIG_PATH"
}
substitutions {
key: "TRIGGER_NAME"
value: "rmgpgab-videoo-app-dev-europe-west1-...--storb"
}
substitutions {
key: "_DEPLOY_REGION"
value: "europe-west1"
}
substitutions {
key: "_ENTRYPOINT"
value: "gunicorn -b :$PORT videoo.wsgi"
}
substitutions {
key: "_GCR_HOSTNAME"
value: "eu.gcr.io"
}
substitutions {
key: "_LABELS"
value: "gcb-trigger-id=...-d5fd-47b7-8949-..."
}
substitutions {
key: "_PLATFORM"
value: "managed"
}
substitutions {
key: "_SERVICE_NAME"
value: "videoo-app-dev"
}
substitutions {
key: "_TRIGGER_ID"
value: "...-d5fd-47b7-8949-..."
}
以下代碼未按預期工作:
def sample_list_builds():
# Create a client
client = cloudbuild_v1.CloudBuildClient()
# Initialize request argument(s)
request = cloudbuild_v1.ListBuildsRequest(
project_id=settings.PROJECT_ID,
)
# Make the request
page_result = client.list_builds(request=request)
# Handle the response
for response in page_result:
print(response.status)
if response.status=="Status.SUCCESS":
print(response.results['images']['name'])
break
如何將狀態字段與成功案例進行比較?
您應該在答案中有 status 和 status_detail 。
如果您導入構建類型
from google.cloud.devtools.cloudbuild_v1.types import Build
您應該能夠使用例如Build.Status.SUCCESS
並進行比較。
如此處所述,當您的構建的 state 發生更改時,Cloud Build 會在 Google Pub/Sub 主題上發布消息。 查看 Pull 訂閱也可能會有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.