Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gcloud command line get default project_id

People also ask

How use gcloud command line?

Download and install the gcloud CLI If you're using Cloud Shell, the gcloud CLI is available automatically and you don't need to install it. Otherwise, download and install the gcloud CLI and then initialize it. By default, the gcloud CLI installs commands that are at the General Availability level.

What command can be used in the Google Cloud Shell to set the default project?

Download the config file from https://cloud.google.com. Run the gcloud init command. Feedback: The gcloud init command sets your login, your default project, and your default region and zone.


The easiest way to do this is to use the --format flag on gcloud.

gcloud config list --format 'value(core.project)' 2>/dev/null

The --format flag is available on all commands and gives you full control over what is printed, and how it is formatted.

You can see this help page for full info: gcloud topic formats


Thanks to comment from Tim Swast above, I was able to use export PROJECT_ID=$(gcloud config get-value project) to get the project ID.

Running gcloud config get-value project prints the following on screen:

Your active configuration is: [default]

my-project-id

You can also run gcloud config get-value project 2> /dev/null to print just the project ID and suppress other warnings/errors.


With Google Cloud SDK 266.0.0 you can use following command:

gcloud config get-value project

Not exactly the gcloud command you specified, but will return you the currently configured project:

gcloud info |tr -d '[]' | awk '/project:/ {print $2}'

Works for account, zone and region as well.


From Cloud Shell or any machine where Cloud SDK is installed, we can use:

echo $DEVSHELL_PROJECT_ID

And as shown in the below screenshot.

A command to get GCP project ID