I’m looking for a gcloud
one-liner to get the default project ID ($GCP_PROJECT_ID
).
The list
command gives me:
gcloud config list core/project
#=>
[core]
project = $GCP_PROJECT_ID
Your active configuration is: [default]
While I only want the following output:
gcloud . . .
#=>
$GCP_PROJECT_ID
The easiest way to do this is to use the --format
flag with 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