How to change the project in GCP using CLI commands

前端 未结 16 1981
爱一瞬间的悲伤
爱一瞬间的悲伤 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: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}]}"
    }
    

提交回复
热议问题