如何使用cli命令,而不是手动使用gcloud init,将GCP(谷歌云平台)账户下当前正在运行的项目修改为其他项目?
Gcloud项目列表将列出在我的帐户上运行的项目。我想使用cli命令将当前项目更改为列表中的任何其他项目。
如何使用cli命令,而不是手动使用gcloud init,将GCP(谷歌云平台)账户下当前正在运行的项目修改为其他项目?
Gcloud项目列表将列出在我的帐户上运行的项目。我想使用cli命令将当前项目更改为列表中的任何其他项目。
当前回答
要将现有项目更新到另一个项目,您可以使用以下命令行:
gcloud项目更新PROJECT_ID——name= name
NAME:将是项目的新名称。
其他回答
gcloud config set project $MY_PROJECT_ID
#=>
Updated property [core/project].
您还可以设置环境变量$CLOUDSDK_CORE_PROJECT。
我确实更喜欢别名,对于可能需要多个命令的东西,根据您的项目需求,我更喜欢函数……
例子
function switchGCPProject() {
gcloud config set project [Project Name]
// if you are using GKE use the following
gcloud config set container/cluster [Cluster Name]
// if you are using GCE use the following
gcloud config set compute/zone [Zone]
gcloud config set compute/region [region]
// if you are using GKE use the following
gcloud container clusters get-credentials [cluster name] --zone [Zone] --project [project name]
export GOOGLE_APPLICATION_CREDENTIALS=path-to-credentials.json
}
要将现有项目更新到另一个项目,您可以使用以下命令行:
gcloud项目更新PROJECT_ID——name= name
NAME:将是项目的新名称。
做以下几点:
1 - gcloud认证列表 2 - gcloud项目列表 3 - gcloud配置项目*投影* (将项目id替换为实际项目id)
通过运行:gcloud projects list检查可用的项目。这将为您提供一个可以访问的项目列表。 执行命令gcloud config set project <project-id>。
另外,我建议在对gcloud配置进行任何更改之前检查活动配置。您可以通过运行:gcloud config list来完成