问题
Is there a command for this? I can do
gcloud projects describe my-project
...and check for an error. But that's not specific to not-found errors. I thought to check the exit code, and I do see that there are some different error codes:
$ gcloud projects describe some-nonexistent-project-foo; echo $?
130
$ gcloud projecx typo typo; echo $?
2
...but without any documentation, I don't want to trust that 130 specifically means not found. Could mean any server error for all I know.
So, is there any way to check for existence? Another command?
Ultimately I'm doing this because I want to create a project if it doesn't exist. So if there's another way to do that (again, without ignoring legitimate errors), then I don't care as much about checking for existence.
回答1:
Try gcloud projects list to see all projects. To check for one project, do gcloud projects list --filter my-project. For a full list of other possible arguments and commands, see the documentation, which is very good.
来源:https://stackoverflow.com/questions/51391530/gcloud-command-to-check-if-project-exists