错误:无法加载默认凭据。上下文:firebase登录:ci和firebase身份验证:导出
免责声明:有很多类似的问题提到了相同的错误消息,但我读了很多,没有一个与我的上下文相关 我正在尝试使用命令自动导出Firebase身份验证数据库。该命令在我的本地机器上完美地执行。但当我尝试在CI上运行它时,它失败,并显示以下错误消息:错误:无法加载默认凭据。上下文:firebase登录:ci和firebase身份验证:导出,firebase,firebase-authentication,gitlab-ci,Firebase,Firebase Authentication,Gitlab Ci,免责声明:有很多类似的问题提到了相同的错误消息,但我读了很多,没有一个与我的上下文相关 我正在尝试使用命令自动导出Firebase身份验证数据库。该命令在我的本地机器上完美地执行。但当我尝试在CI上运行它时,它失败,并显示以下错误消息: [2021-04-27T20:48:23.188Z] > command requires scopes: ["email","openid","https://www.googleapis.com/aut
[2021-04-27T20:48:23.188Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2021-04-27T20:48:26.208Z] Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:160:19)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at runNextTicks (internal/process/task_queues.js:66:3)
at listOnTimeout (internal/timers.js:518:9)
at processTimers (internal/timers.js:492:7)
at async GoogleAuth.getClient (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17)
at async GoogleAuth.getAccessToken (/home/node/.npm-global/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:524:24)
Error: An unexpected error has occurred.
我正在尝试使用.gitlab-ci.yml文件在中运行此命令。为了实现这一点,我知道我需要使用命令进行身份验证。我这样做了,我知道令牌是有效的,因为我的.gitlab-ci.yml工作中的其他firebase
命令,例如firebase use
和firebase deploy
以下是my.gitlab-ci.yml的简化版本:
阶段:
-stg_备份
jb_auth_备份:
阶段:stg_备份
图片:devillex/docker firebase
仅:
-时间表
脚本:
-firebase使用——令牌$MY\u CI\u firebase\u部署\u密钥$MY\u firebase\u项目
-mkdir备份
-firebase--debug auth:export backups/my-auth-backup.json--format=json
人工产品:
路径:
-备份
将环境变量正确设置为
我尝试刷新我的firebase身份验证令牌,但没有成功。我试着在下面的帖子中阅读关于错误消息的内容,但由于他们谈到了谷歌云平台服务帐户,我不确定这与firebase身份验证令牌有何关系
--token
应传递给每个firebase
命令:
- 将令牌存储为环境变量FIREBASE_token。你的 系统将自动使用令牌
- 在CI中使用--token标志运行所有firebase命令 系统。令牌加载的优先顺序是标志、环境 变量,所需的Firebase项目
--token
被传递到firebase use
命令,但它没有被传递到firebase auth:export
命令。不要假设firebase use
不仅保存活动项目选择,还保存令牌。根据《firebase帮助使用》,其唯一目的是“为您的工作目录设置活动firebase项目”。它没有说明如何设置活动令牌
我已确认以下内容。实际上,gitlab-ci.yml脚本已成功导出Firebase身份验证数据库:
阶段:
-stg_备份
jb_auth_备份:
阶段:stg_备份
图片:devillex/docker firebase
仅:
-时间表
脚本:
-firebase--令牌$MY_CI_firebase_DEPLOY_密钥使用$MY_firebase_项目
-mkdir备份
-firebase--令牌$MY\u CI\u firebase\u DEPLOY\u KEY auth:export backups/MY-auth-backup.json--format=json
人工产品:
路径:
-备份
请注意,firebase use
和firebase auth:export
命令的语法都已从原来的.gitlab-ci.yml更改。他们现在都将--token
放在firebase
可执行命令之后。根据firebase帮助
,这更符合文档中的语法。它说正确的语法是firebase[options][command]
,其中--token
是选项之一
事实上,甚至不清楚firebase use--token
是否注意到了token,因为它在use
命令之后而不是之前。很遗憾,firebase-use--token
不只是抛出一个错误,让用户知道--token
属于firebase
的[options]
而不是[options]
的[options]