gcloud命令检查项目是否存在 [英] gcloud command to check if project exists
问题描述
有命令吗?我能做
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
...但是没有任何文档,我不想相信130表示没有找到.就我所知,可能意味着任何服务器错误.
...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.
推荐答案
尝试使用gcloud projects list
查看所有项目.要检查一个项目,请执行gcloud projects list --filter my-project
.有关其他可能的参数和命令的完整列表,请参见文档 ,这非常好.
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.
这篇关于gcloud命令检查项目是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!