FIREBASE_TOKEN 在 CI/CD gitlab 中已弃用

Gae*_*zio 1 deployment gitlab firebase cicd

我在部署网络应用程序时遇到警告,firebase 告诉我该令牌即将被弃用,我建议使用 google 凭据。

cicd输出

您对如何设置 gitlab 管道以使用 google 凭证有什么建议吗?我还没有找到这方面的指南。这是我的剧本。

gitlab脚本

目前我已经配置了一个包含令牌的 gitlab 环境变量并且它可以工作(有警告)。

gitlab firebase 令牌

我尝试在 gitlab 设置中设置 GOOGLE_APPLICATION_CREDENTIALS 环境变量,但我不知道用于部署的 firebase 命令。

Gae*_*zio 5

我找到了使用 GOOGLE_APPLICATION_CREDENTIALS 从 gitlab 进行部署的方法。这是我的脚本:

image: node:14.18.0-alpine

before_script:
  - npm i -g firebase-tools
  - echo $FIARD_PRIVATE_KEY > "/private-key.json"
  - export GOOGLE_APPLICATION_CREDENTIALS="/private-key.json"

stages:
  - staging
  - production

deploy_staging:
  stage: staging
  when: manual
  script:
    - firebase use staging
    - firebase deploy --only hosting:ineffe-business-site-staging
    - echo "Deploying hosting staging finished!"
  only:
    - master
  environment:
    name: staging
    url: https://staging-business-ineffe.firebaseapp.com/

deploy_production:
  stage: production
  when: manual
  script:
    - firebase use default
    - firebase deploy --only hosting:ineffe-business-site-prod
    - echo "Deploying hosting production finished!"
  only:
    - master
  environment:
    name: production
    url: https://business-ineffe-com.firebaseapp.com/
Run Code Online (Sandbox Code Playgroud)

我根据环境(暂存和生产)在 gitlab 上创建了环境变量,并且它有效。这些变量包含 Google 提供的身份验证 json。

gitlab环境变量

我发布了这个答案,如果它对某人有用的话。