How to get the URL of deployed service programmatically in CI environments? The URL does get's logged after successful deploy but what if I want to extract and use the URL programmatically, as part of post deploy needs, e.g. posting the URL for acceptance test.
Access to public objects All requests to the storage.cloud.google.com URI require authentication.
Enable it by visiting https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com/overview?project=<project-number> then retry.
Simply use the flag: --format='value(status.url)'
with gcloud run services describe
Here is the entire command:
$ gcloud run services describe SERVICE --platform managed --region REGION --format 'value(status.url)'
Extending Steren's answer:
With these Bash commands you can get url and save it in Secrets Manager:
First create empty Secret:
gcloud secrets create "CLOUDRUN_URL" --project $PROJECT_ID --replication-policy=automatic
Then:
gcloud run services describe $APP_NAME --platform managed --region $CLOUD_REGION --format 'value(status.url)' --project $PROJECT_ID | gcloud secrets versions add "CLOUDRUN_URL" --data-file=- --project $PROJECT_ID
or version with added "/some/address"
CLOUDRUN_URL=$(gcloud run services describe $APP_NAME --platform managed --region $CLOUD_REGION --format 'value(status.url)' --project $PROJECT_ID) # capture first string.
echo "$CLOUDRUN_URL/some/address/" | gcloud secrets versions add "CLOUDRUN_URL" --data-file=- --project $PROJECT_ID
And then you can load it as needed from Secrets Manager:
export CLOUDRUN_URL=$(gcloud secrets versions access latest --secret="CLOUDRUN_URL" --project $PROJECT_ID )
There are several ways to get the desired information:
curl -i https://[REGION]-run.googleapis.com/apis/serving.knative.dev/v1/namespaces/[PROJECT_NAME]/services/[CLOUD_RUN_SERVICE_NAME] -H "Authorization: Bearer [YOUR-BEARER-TOKEN]" | tail -n +13 | jq -r ".status.url"
gcloud run services list --platform managed | awk 'NR==2 {print $4}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With