首页 > 解决方案 > 无法使用 bash 脚本设置 gcloud 项目

问题描述

我基本上是在尝试通过调用 bash 脚本文件来设置谷歌项目 ID,但无法这样做。但是,如果我单独运行该命令,它就可以工作。我通过激活 gcloud shell 终端来调用 bash 脚本文件。

命令:./init.sh vibrant-brand-298097 vibrant-bucket terraform-trigger /var/dev/dev.tfvars

初始化.sh:

#!/bin/bash
PROJECT_ID=$1

#Bucket for storing state
BUCKET_NAME=$2

# Based on this value cloud build will set trigger on the test repository
TERRAFORM_TRIGGER=$3

# This is the path to the env vars file, terraform will pick variables from this path for the given env.
TERRAFORM_VAR_FILE_PATH=$4

#Check if all the args were passed
if [ $# -ne 4 ]; then
  echo "Not all the argumets were passed"
  exit 0
fi

echo "setting project to $PROJECT_ID"
gcloud config set project $PROJECT_ID

echo "Creating bucket $BUCKET_NAME"
gsutil mb -b on  gs://$BUCKET_NAME/

错误日志:

setting project to
ERROR: (gcloud.config.set) argument VALUE: Must be specified.
Usage: gcloud config set SECTION/PROPERTY VALUE [optional flags]
  optional flags may be  --help | --installation

标签: bashgoogle-cloud-platformgcloud

解决方案


推荐阅读