How to get or generate deploy URL for Google Cloud Run services

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)'

There are several ways to get the desired information:

  1. You can use the namespaces.services.get method from Cloud Run's API and a curl command. Notice that it will require an Authentication Header and an OAuth scope.
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"
  1. You can use the gcloud run services list command in one of your build steps to get the desired value. For example if your service is fully managed you can use the following command to get the Cloud Run service that was last updated.:
gcloud run services list --platform managed | awk 'NR==2 {print $4}'
  1. Build a script using the Goolge API Client libraries (e.g. the Cloud Run Google API Client for Python).

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 )