One of the nice things with Cloud Run is that when you deploy your services, you get a URL like https://myservice-8oafjf26aq-ew.a.run.app/, with a certificate, on the run.app domain name, etc.
You see the name of the service: myservice, the region shortcut where it was deployed: ew (Europe West), and then .a.run.app. However, you can't guess ahead of time what the final URL will be, as there is a randomly generated part in the URL (here: 8oafjf26aq). Let's see how we can discover this whole URL.
From my terminal, I can request the list of deployed services (here, on the fully managed Cloud Run):
gcloud run services list --platform managed
It's going to show me something like the following output:
SERVICE REGION URL LAST DEPLOYED BY LAST DEPLOYED AT
✔ myservice europe-west1 https://myservice-8oafjf26aq-ew.a.run.app email@example.com 2019-11-20T15:26:39.442Z
When describing the specific service (I had to specify the region as well, but you can set it by default if needed to avoid repeating yourself):
gcloud run services describe myservice --platform managed --region europe-west1
✔ Service hello in region europe-west1
100% LATEST (currently myservice-00002-dox)
Last updated on 2019-11-20T15:26:39.442Z by firstname.lastname@example.org:
So instead of parsing that ourselves somehow, there's a built-in way to get just the info we want, with the useful --format flag:
gcloud run services describe myservice --format='value(status.url)' --platform managed --region europe-west1
This time, in output, you'll get just the URL, which you can then export or reuse with other commands.
The glcoud command provides three useful mechanisms to filter, format, or project the output and values returned. Here, we took advantage of format.