是否可以自动化Gsutil登录?

Usm*_*ail 4 google-cloud-storage

是否可以自动将基于gsutil的文件上传到谷歌云存储,以便登录时不需要用户干预?

我的用例是有一个jenkins作业,它会轮询SCM位置以更改一组文件.如果它检测到任何更改,则会将所有文件上传到特定的Google云端存储分区.

fej*_*jta 9

配置凭据后,gsutil无需进一步干预.我怀疑你gsutil configure以用户X身份运行,但Jenkins以用户Y身份运行~jenkins/.boto.因此,不存在.如果将.boto文件放在正确的位置,则应该全部设置.

另一种方法是使用多个.boto文件,然后告诉gsutil使用哪个BOTO_CONFIG环境变量:

gsutil config  # complete oauth flow
cp ~/.boto /path/to/existing.boto
# detect that we need to upload
BOTO_CONFIG=/path/to/existing.boto gsutil -m cp files gs://bucket
Run Code Online (Sandbox Code Playgroud)

我经常使用此模式将gsutil与多个帐户一起使用:

gsutil config  # complete oauth flow for user A
mv ~/.boto user-a.boto
gsutil config  # complete oauth flow for user B
mv ~/.boto user-b.boto
BOTO_CONFIG=user-a.boto gsutil cp a-file gs://a-bucket
BOTO_CONFIG=user-b.boto gsutil cp b-file gs//b-bucket
Run Code Online (Sandbox Code Playgroud)

  • gsutil config仍然是配置独立gsutil的正确方法,但gcloud auth login是配置通过Google Cloud SDK分发的gsutil的正确方法 (3认同)