根据https://cloud.google.com/sdk/gcloud/reference/init gcloud init myproject
命令的文档不起作用。
google-cloud> gcloud init myproject
Initialized gcloud directory in [/Users/arungupta/workspaces/google-cloud/myproject/.gcloud].
Cloning [https://source.developers.google.com/p/myproject/r/default] into [default].
Cloning into '/Users/arungupta/workspaces/google-cloud/myproject/default'...
fatal: remote error: Repository not found.
You may need to create a repository for this project using the Source Code tab at https://console.developers.google.com
ERROR: Command '['git', 'clone', 'https://source.developers.google.com/p/myproject/r/default', '/Users/arungupta/workspaces/google-cloud/myproject/default', '--config', 'credential.helper=gcloud.sh']' returned non-zero exit status 128
ERROR: Unable to initialize project [myproject], cleaning up [/Users/arungupta/workspaces/google-cloud/myproject].
ERROR: (gcloud.init) Unable to initialize project [myproject].
使用gcloud init minecraft-server --project minecraft-server-183
创建项目会创建名为minecraft-server-183
的项目。
这样创建的项目在https://console.developers.google.com/project处无法显示。
创建新项目的正确gcloud
命令是什么,无需进入控制台?
答案 0 :(得分:7)
答案 1 :(得分:0)
更新截至2016年10月24日@poolie表示Stephen回答中提及的gcloud
命令现在可以公开访问,我会在这里留下这个答案其他一些使用建议。
我也遇到了问题,@Stephan Weinberg的评论非常气馁,但我注意到gcloud init
在做{...}}的时候会问到在哪里放置"默认"库。所以我查看了那个配置,看到它与所记录的内容略有不同。
尝试推送到https://source.developers.google.com/p/YOUR-PROJECT-NAME/r/default
代替它,它对我有用!
答案 2 :(得分:0)
这是一个脚本,它将创建一个可由用户编辑的项目(出于多种原因,例如服务帐户的可审计性,您可能希望创建每个用户的项目):
#!/bin/bash
if [ "$#" -lt 3 ]; then
echo "Usage: ./create_projects.sh billingid project-prefix email1 [email2 [email3 ...]]]"
echo " eg: ./create_projects.sh 0X0X0X-0X0X0X-0X0X0X learnml-20170106 somebody@gmail.com someother@gmail.com"
exit
fi
ACCOUNT_ID=$1
shift
PROJECT_PREFIX=$1
shift
EMAILS=$@
gcloud components update
gcloud components install alpha
for EMAIL in $EMAILS; do
PROJECT_ID=$(echo "${PROJECT_PREFIX}-${EMAIL}" | sed 's/@/-/g' | sed 's/\./-/g' | cut -c 1-30)
echo "Creating project $PROJECT_ID for $EMAIL ... "
# Create project
gcloud alpha projects create $PROJECT_ID
# Add user to project
gcloud alpha projects get-iam-policy $PROJECT_ID --format=json > iam.json.orig
cat iam.json.orig | sed s'/"bindings": \[/"bindings": \[ \{"members": \["user:'$EMAIL'"\],"role": "roles\/editor"\},/g' > iam.json.new
gcloud alpha projects set-iam-policy $PROJECT_ID iam.json.new
# Set billing id of project
gcloud alpha billing accounts projects link $PROJECT_ID --account-id=$ACCOUNT_ID
done
脚本的说明是在媒介上:https://medium.com/google-cloud/how-to-automate-project-creation-using-gcloud-4e71d9a70047#.t58mss3co和上面代码的github链接(例如,当它转到beta / GA时,我将更新它以删除alpha):{ {3}}