Gcloud command line get default project_id

Ali SAID OMAR picture Ali SAID OMAR · Feb 24, 2016 · Viewed 36.5k times · Source

I'm looking for a one-liner to get the default project id

with gcloud config list core/project give me

Your active configuration is: [default]
[core]
project = myproject_id

While I want to have only myproject_id. The goal is to use the result in a script.

Answer

Mark picture Mark · Feb 24, 2016

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