简体   繁体   中英

How to check which gcloud project is active

To see all your gcloud projects you use command gcloud projects list . To switch to a specific project, you use gcloud config set project PROJECT_ID .

But what command can you use when you want to check which project is active? By which I mean, on which project was called the set command last?

gcloud config get-value project

You can always type gcloud config --help

There's a very cool and well-hidden interactive tool: gcloud beta interactive that will help with gcloud command completion.

Personally, I recommend not using configurations to hold default values (for eg project ) in order to (help) avoid "To which project did I just apply that command?" issues.

IMO, it's much better to be more explicit and I prefer:

gcloud ... --project=${PROJECT}

If, like me, you put the project value in a variable, you can still make mistakes but it is easier to avoid them.

You can also define sets of configurations and then use gcloud... --configuration=${CONFIG} and this works too as long as you don't set values in the default config

  1. You can use gcloud projects list --filter='lifecycleState:ACTIVE' to get all active projects.

  2. Or you can list them all showing lifecyclestate and filter with grep or other bash stuff:

$ gcloud projects list --format="table(projectNumber,projectId,createTime.date(tz=LOCAL),lifecycleState)" --limit 10
PROJECT_NUMBER  PROJECT_ID                 CREATE_TIME          LIFECYCLE_STATE
310270846648    again-testing-no-notebook  2022-12-11T07:03:03  ACTIVE
[...]

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM