bash - gcloud:是否可以根据当前文件夹更改默认项目?

标签 bash config gcloud direnv

我正在开发多个 gcloud 项目,我厌倦了每次需要调用命令时都必须输入 --project XYZ,或者更糟糕的是命令执行错误项目,如果我忘记添加它的话。

最佳答案

是的,使用 gcloud configurationsdirenv 一起.

创建配置(这也将激活它):

  • gcloud config configurations create <cool_new_config>
  • gcloud config set project <project>

安装direnv 。把它挂进你的壳里。在 bash 中我使用 ~/.bash_profile而不是定向~/.bashrc .

导航到您想要进行切换的项目文件夹。

  • 创建一个名为 .envrc 的文件
  • 添加行export CLOUDSDK_ACTIVE_CONFIG_NAME=<cool_new_config>
  • 白名单文件 direnv allow

验证功能:

  • 打开一个新的终端窗口
  • 激活默认/先前配置
  • 导航至文件夹
  • 确认 gcloud config configurations list

可选:重建其余配置

  • 查看所有配置:gcloud config configurations list
  • 描述旧配置 gcloud config configurations describe <default>
  • 登录:gcloud auth login
  • 设置区域:gcloud config set compute/region <us-central1>
  • 设置区域:gcloud config set compute/zone <us-central1-a>
  • 等等

关于bash - gcloud:是否可以根据当前文件夹更改默认项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56781493/

相关文章:

macos - 请求用户访问 `root` 以更新 `/etc/paths.d`

python-2.7 - 使用多个版本的 py2.7 安装 Google Cloud SDK 时出现 sqlite3 错误

python - WARN : Tried to pass invalid video frame, 标记为损坏的 : Your frame has data type int64, 但我们需要 uint8

node.js - 将 gcloud createReadStream 加载到 nodejs 中的变量中

bash - 如何执行shell命令

c# - 使用 .NET Core 在 Linux 中通过 "/bin/bash"执行 .sh(bash 脚本)文件

mysql - 执行动态mysql查询失败

grails - 将用户保留在Grails的Config.groovy列表中

c - 使用 xml 配置文件 - 简单的映射方法?

bash - 删除目录中的现有文件