是否可以自动化 Gsutil 登录? [英] Is it possible to automate Gsutil login?

查看:28
本文介绍了是否可以自动化 Gsutil 登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to automate gsutil based file upload to google cloud store so that the user intervention is not required for login?

我的用例是有一个 jenkins 作业,它轮询 SCM 位置以查找对一组文件的更改.如果它检测到任何更改,它会将所有文件上传到特定的 Google Cloud Store 存储桶.

My usecase is to have a jenkins job which polls a SCM location for changes to a set of files. If it detects any changes it will upload all files to a specific Google Cloud Store bucket.

推荐答案

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

After you configure your credentials once gsutil requires no further intervention. I suspect that you ran gsutil configure as user X but Jenkins runs as user Y. As a result, ~jenkins/.boto does not exist. If you place the .boto file in the right location you should be all set.

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

Another alternative is to use multiple .boto files and then tell gsutil which one to use with the BOTO_CONFIG environment variable:

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

我经常使用这种模式将 gsutil 用于多个帐户:

I frequently use this pattern to use gsutil with multiple accounts:

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

这篇关于是否可以自动化 Gsutil 登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆