GitlabCI:无法通过身份验证,您已运行Firebase登录吗?

时间:2020-06-27 21:59:07

标签: firebase gitlab gitlab-ci firebase-cli

我遵循this tutorial来使用Firebase和Gitlab CI部署我的Web项目。

我使用此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/**/*

我将FIREBASE_TOKEN变量存储在我的GitLab中,分别为protectedmasked

但是当它在管道中运行时,它失败并返回以下错误消息:

$ 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

我不知道为什么:

身份验证失败,您运行Firebase登录吗?

因为我使用令牌使用--token标志进行身份验证。

有人知道为什么会出现此错误吗?

2 个答案:

答案 0 :(得分:0)

好的,这是一个虚拟错误。由于选中了$FIREBASE_TOKEN选项,因此未考虑我的变量Protect variable (Export variable to pipelines running on protected branches and tags only.)。但是我正在开发一个功能分支,以测试未受保护的分支。

答案 1 :(得分:0)

我遇到了同样的错误,但通过 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。“