Gitlab CI:验证失败,你 运行 firebase 登录了吗?
GitlabCI: Failed to authenticate, have you run firebase login?
我按照 this tutorial 使用 firebase 和 Gitlab 部署了我的 web 项目 CI。
我使用这个 conf 在 firebase 上部署:
# .gitlab-ci.yml
deploy:
stage: deploy
environment: production
before_script:
- npm i -g firebase-tools
script:
- firebase deploy --token "$FIREBASE_TOKEN" -P "$PROJECT_NAME" --debug
only:
refs:
- master
changes:
- src/**/*
我在我的 GitLab 中将 FIREBASE_TOKEN
变量存储为 protected
和 masked
.
但是当它在管道中 运行 时失败并且 return 此错误消息:
$ firebase deploy --token "$FIREBASE_TOKEN" -P "$PROJECT_NAME" --debug
[2020-06-27T21:26:52.339Z] > 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"]
[2020-06-27T21:26:55.356Z] Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/usr/local/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 (/usr/local/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17)
at async GoogleAuth.getAccessToken (/usr/local/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:524:24)
Error: Failed to authenticate, have you run firebase login?
ERROR: Job failed: exit code 1
我不知道为什么会得到:
Failed to authenticate, have you run firebase login?
因为我使用令牌通过 --token
标志进行身份验证。
有人知道为什么我会收到此错误吗?
好的,这是一个伪错误。我的变量 $FIREBASE_TOKEN
没有被考虑在内,因为我检查了 Protect variable (Export variable to pipelines running on protected branches and tags only.)
选项。但是我正在开发一个功能分支来测试它不受保护。
我遇到了同样的错误,但是通过GitHub Actions。解决方案是在本地 运行 命令 firebase init hosting:github
,如 https://github.com/marketplace/actions/deploy-to-firebase-hosting 处的文档所示。登录后,这将在您的存储库中为您设置一个 GitHub Secret。
以下内容摘自上述文档:
“将此令牌存储为加密密钥非常重要,以防止意外访问您的 Firebase 项目。将其设置在存储库设置的“机密”区域并将其添加为 FIREBASE_SERVICE_ACCOUNT:https://github.com/USERNAME/REPOSITORY/settings/secrets."
我按照 this tutorial 使用 firebase 和 Gitlab 部署了我的 web 项目 CI。
我使用这个 conf 在 firebase 上部署:
# .gitlab-ci.yml
deploy:
stage: deploy
environment: production
before_script:
- npm i -g firebase-tools
script:
- firebase deploy --token "$FIREBASE_TOKEN" -P "$PROJECT_NAME" --debug
only:
refs:
- master
changes:
- src/**/*
我在我的 GitLab 中将 FIREBASE_TOKEN
变量存储为 protected
和 masked
.
但是当它在管道中 运行 时失败并且 return 此错误消息:
$ firebase deploy --token "$FIREBASE_TOKEN" -P "$PROJECT_NAME" --debug
[2020-06-27T21:26:52.339Z] > 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"]
[2020-06-27T21:26:55.356Z] Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/usr/local/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 (/usr/local/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:502:17)
at async GoogleAuth.getAccessToken (/usr/local/lib/node_modules/firebase-tools/node_modules/google-auth-library/build/src/auth/googleauth.js:524:24)
Error: Failed to authenticate, have you run firebase login?
ERROR: Job failed: exit code 1
我不知道为什么会得到:
Failed to authenticate, have you run firebase login?
因为我使用令牌通过 --token
标志进行身份验证。
有人知道为什么我会收到此错误吗?
好的,这是一个伪错误。我的变量 $FIREBASE_TOKEN
没有被考虑在内,因为我检查了 Protect variable (Export variable to pipelines running on protected branches and tags only.)
选项。但是我正在开发一个功能分支来测试它不受保护。
我遇到了同样的错误,但是通过GitHub Actions。解决方案是在本地 运行 命令 firebase init hosting:github
,如 https://github.com/marketplace/actions/deploy-to-firebase-hosting 处的文档所示。登录后,这将在您的存储库中为您设置一个 GitHub Secret。
以下内容摘自上述文档:
“将此令牌存储为加密密钥非常重要,以防止意外访问您的 Firebase 项目。将其设置在存储库设置的“机密”区域并将其添加为 FIREBASE_SERVICE_ACCOUNT:https://github.com/USERNAME/REPOSITORY/settings/secrets."