How to change the project in GCP using CLI commands

前端 未结 16 1707
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 18:07

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

相关标签:
16条回答
  • 2021-01-29 18:36

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

    0 讨论(0)
  • 2021-01-29 18:37

    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 "\""}'
    
    0 讨论(0)
  • 2021-01-29 18:37

    Just use the gcloud projects list to get the project you have . Get the PROJECT_ID of the poject to use After that use gcloud set project --project=PROJECT_ID to set the project.

    0 讨论(0)
  • 2021-01-29 18:39

    You can try: gcloud config set project [project_id]

    0 讨论(0)
  • 2021-01-29 18:40
    gcloud config set project my-project
    

    You may also set the environment variable $CLOUDSDK_CORE_PROJECT.

    0 讨论(0)
  • 2021-01-29 18:42

    add this below script in ~/.bashrc and do please replace project name(projectname) with whatever the name you needed

    function s() {
            array=($(gcloud projects list | awk /projectname/'{print $1}'))
            for i in "${!array[@]}";do printf "%s=%s\n" "$i" "${array[$i]}";done
            echo -e "\nenter the number to switch project:\c"
            read project
            [ ${array[${project}]} ] || { echo "project not exists"; exit 2; }
            printf "\n**** Running: gcloud config set project ${array[${project}]} *****\n\n"
            eval "gcloud config set project ${array[${project}]}"
    }
    
    0 讨论(0)
提交回复
热议问题