gcloud command to check if project exists

笑着哭i 提交于 2019-12-11 17:49:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!