如何使用cli命令,而不是手动使用gcloud init,将GCP(谷歌云平台)账户下当前正在运行的项目修改为其他项目?
Gcloud项目列表将列出在我的帐户上运行的项目。我想使用cli命令将当前项目更改为列表中的任何其他项目。
如何使用cli命令,而不是手动使用gcloud init,将GCP(谷歌云平台)账户下当前正在运行的项目修改为其他项目?
Gcloud项目列表将列出在我的帐户上运行的项目。我想使用cli命令将当前项目更改为列表中的任何其他项目。
当前回答
我确实更喜欢别名,对于可能需要多个命令的东西,根据您的项目需求,我更喜欢函数……
例子
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 auth list
* account 1
account 2
如果不是,则更改项目帐户:
gcloud config set account `ACCOUNT`
根据不同的帐户,项目列表将有所不同:
gcloud projects list
- project 1
- project 2...
切换到预定项目:
gcloud config set project `PROJECT ID`
gcloud config set project $MY_PROJECT_ID
#=>
Updated property [core/project].
您还可以设置环境变量$CLOUDSDK_CORE_PROJECT。
可以使用gcloud命令更改项目:
gcloud config set project <your_project_name>
只需使用gcloud项目列表来获取您拥有的项目。获取要使用的对象的PROJECT_ID 之后使用gcloud set project——project=PROJECT_ID来设置项目。
您可以尝试:gcloud config set project [project_id]