google cloud platform

Google cloud shell command to get the default PROJECT_ID – GCP

This tutorial guides you on how to get the default project_id of Google Cloud Platform and export it to a variable. So that the resulting variable which contains the PROJECT_ID can be used in the other commands or scripts.

Get the default PROJECT_ID GCP

Project ID is the unique identifier of your project in GCP (Google Cloud Platform). It can be used by Google APIs. If you don’t specify it will be created automatically.

If you would like to get the default project_id from the GCP cloud shell, then run the following gcloud command.

$ gcloud info --format='value(config.project)'

sne5g21

Then, if you would like to export the default project_id to a variable called PROJECT_ID, so that you can use them in other commands or scripts, you need to run the following export command.

sneppets@cloudshell:~ (sne5g21)$ export PROJECT_ID=$(gcloud info --format='value(config.project)')

Verify if the variable is set with the default project_id.

sneppets@cloudshell:~ (sne5g21)$ echo $PROJECT_ID

sne5g21

Note, we are trying to use –format flag with gcloud info command to achieve this. For more details about gcloud info command and gcloud wide flags supported, please check this link gcloud info details.

Locate the project ID from console

To locate your Project ID through GCP console follow the below steps:

  1. First, go to the GCP Console.
  2. From the projects list, the Names and ID’s for all the projects you are member of are displayed. You can find the project_id from this list as well.

That’s it. You had learnt how to get the default project_id using gcloud info command and from GCP console.

Hope it helped 🙂

References

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments