Fetch CloudRun URL via Python client API

139 views
Skip to first unread message

Raghav Arora

unread,
Jan 28, 2022, 4:38:59 AM1/28/22
to gce-discussion
Hi All,

I want to fetch a CloudRun service's URL via a Python client if its possible in GCP ?
Is there any API / sample code / python client that has the capability?

In a crux, I am triggering a build via Cloud Build (gcloud builds submit) but somehow below command doesn't give me anything - instead it errors out saying the projectid is not correct.

cloudRunAppUri=$( gcloud run services describe <service-name> --platform managed --project <projectId> --region <region> --format 'value(status.url)' )

It errors out with:
ERROR: (gcloud) The project property must be set to a valid project ID, not the project name ["<projectId I gave>"]

So I am looking to instead leverage Python based script to fetch Cloud Run instance's URL if its possible in some way or the other please?

Any leads will be appreciated.

Thanks,
Raghav Arora

Jose Otero Perez

unread,
Feb 1, 2022, 5:04:16 AM2/1/22
to gce-discussion
Hello,

I understand that the command [1] should work to retrieve the Uri as explained in [2]. 


Best Regards,
Jose,
------

[1]: gcloud run services describe SERVICE --format 'value(status.url)'


Raghav Arora

unread,
Feb 1, 2022, 5:13:26 AM2/1/22
to gce-discussion
Thanks for responding Jose. And yes I tried this already. It works in isolation but not when executed via a bash shell script file.

cloudRunAppUri=$( gcloud run services describe <service-name> --platform managed --project <projectId> --region <region> --format 'value(status.url)' )

It errors out with:
ERROR: (gcloud) The project property must be set to a valid project ID, not the project name ["<projectId I gave>"]

And I've already tried setting up the projectId in environment by executing:
gcloud auth login
gcloud auth activate-service-account <service-account>
gcloud config set project <projectId>

It all works when executed via a Terminal but it fails to set or find the projectId when executed via a bash shell script file.

Jose Otero Perez

unread,
Feb 2, 2022, 4:07:21 AM2/2/22
to gce-discussion
Hello,

I have created an small bash script an it is working

cloudRunnAppUri=$(gcloud run services describe cloudrunservice --project=xxx --region=us-central1 --format 'value(status.url)')
echo $cloudRunnAppUri

maybe it is related to the use of quotes?

Regards,

Raghav Arora

unread,
Feb 2, 2022, 4:24:18 AM2/2/22
to Jose Otero Perez, gce-discussion
Yes it worked. I found out that I was calling this shell from another shell - and in that 1st shell, I was reading from a JSON file using "jq" and it read by-default values with additional quotes and thus wrong values were being sent to this one.
Now it worked as I corrected the way JQ was reading the values - by adding the "-r" attribute.

And thanks for helping mate - definitely appreciated.

Thanks and Regards,
Raghav


--
© 2018 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Compute Engine Discussion Google Group (gce-dis...@googlegroups.com) to participate in discussions with other members of the Google Compute Engine community and the Google Compute Engine Team.
---
You received this message because you are subscribed to a topic in the Google Groups "gce-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gce-discussion/w7tV3x1UyLM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gce-discussio...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gce-discussion/e97fe593-7064-44c4-8f9b-95087a278e61n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages