How to change the project in gcp using cli command

2020-05-11 20:59发布

How can i change the current running project to another project in GCP (Google Cloud Platform) account using cli commands other than using gcloud init manually.

$gcloud projects list will list the projects running on my account. I want to change the current project to any other project from the list using a cli command.

13条回答
男人必须洒脱
2楼-- · 2020-05-11 21:41

To update your existing project to another project, you can use this command line:

gcloud projects update PROJECT_ID --name=NAME

NAME: will be the new name of your project.

查看更多
The star\"
3楼-- · 2020-05-11 21:43

The selected answer doesn't help if you don't know the name of projects you have added gcloud already. My flow is to list the active projects, then switch to the one I want.

gcloud config configurations list

gcloud config configurations activate [NAME]
where [NAME] is listed from the prior command.

查看更多
你好瞎i
4楼-- · 2020-05-11 21:46

You can try: gcloud config set project [project_id]

查看更多
forever°为你锁心
5楼-- · 2020-05-11 21:47

Make sure you are authenticated with the correct account:

gcloud auth list
* account 1
  account 2

Change to the project's account if not:

gcloud config set account `ACCOUNT`

Depending on the account, the project list will be different:

gcloud projects list

- project 1
- project 2...

Switch to intended project:

gcloud config set project `PROJECT ID`
查看更多
不美不萌又怎样
6楼-- · 2020-05-11 21:48

Check your project by running gcloud config list Then gcloud config set "project name"

查看更多
聊天终结者
7楼-- · 2020-05-11 21:51

I add aliases to the .bash_alaises to switch to a different project.

alias switch_proj1="gcloud config set project ************"

Here is a script to generate aliases :) for all projects listed. Please update the switch_proj to unique project aliases that you can remember.

gcloud projects list | awk '{print "alias switch_proj=\"gcloud config set project " $1 "\""}'
查看更多
登录 后发表回答