如何在 Azure Pipeline 中使用 GOOGLE_APPLICATION_CREDENTIALS 在 firebase 上发布?

问题描述 投票:0回答:2

我在 Azure Devop 上有一个 git 存储库。每次在 master 上发布应用程序时,我都会在 firebase 上发布该应用程序。

这是我当前的 YML:

trigger:
- master

pool:   vmImage: ubuntu-latest

steps:
- task: NodeTool@0   inputs:
    versionSpec: '14.x'   displayName: 'Install Node.js'
- task: CmdLine@2   inputs:
    script: 'npm install -g firebase-tools'
    workingDirectory: '$(Agent.ToolsDirectory)'   displayName: 'install firebase tools'

- script: |
    npm install
    npm run build   displayName: 'npm install and build'

- script: |
    cd functions
    npm install   displayName: 'install functions dependencies'
- task: CmdLine@2   inputs:
    script: 'firebase deploy --token "$(FIREBASE_TOKEN)" -m "$(Build.BuildNumber)"'   displayName: 'firebase publish -m "$(Build.BuildNumber)"'

我最近在工作中注意到以下警告:

!使用

login:ci
令牌进行身份验证已被弃用,并将被弃用 在
firebase-tools
的未来主要版本中删除。相反,使用 带
GOOGLE_APPLICATION_CREDENTIALS
的服务帐户密钥: https://cloud.google.com/docs/authentication/getting-started

这篇文章不太清楚,它更多地讨论了如何访问代码中的内容,而不是直接使用

firebase deploy
。经过一番搜索后,我找到了多个带有 JSON 文件的示例。

但就我而言,有了 git 存储库和管道,我不知道如何继续:

  1. 我不想在 git 存储库中存储带有凭据的文件,它必须是存储在 azure devop 中的某种秘密。
  2. Azure Devop 不允许我存储文件,只能存储字符串

那么,如果我生成了这个 json,我该如何使用它呢?或者还有其他方法吗?

firebase azure azure-devops continuous-integration firebase-cli
2个回答
4
投票

这是您需要做的。

您转到 Firebase 控制台,打开所需的项目,然后执行以下步骤

  1. 单击侧边栏上的引擎图标
  2. 单击“项目设置”链接。
  3. 单击“服务帐户”选项卡。
  4. 单击“生成新私钥”按钮下载包含服务帐户凭据的 JSON 文件。

p.s.:这是一张显示每个步骤所在位置的图像。对不起,葡萄牙语图片😅,我来自巴西。

然后,您将使用刚刚下载的 json 文件的内容在 Azure DevOps 管道中创建一个名为

GOOGLE_APPLICATION_CREDENTIALS
的变量。就像下面的图片一样。

最后一步是将部署步骤包含在管道中。它看起来像这样:

- script: |
    echo $GOOGLE_APPLICATION_CREDENTIALS > $HOME/gcloud.json
    export GOOGLE_APPLICATION_CREDENTIALS=$HOME/gcloud.json
    firebase deploy --only hosting
  displayName: 'Deploy to Firebase Hosting'

假设您的项目已使用

.firebaserc
firebase.json
文件正确设置,一切都应该正常工作。

p.s.:完成所有设置后,请记住在 Azure DevOps 变量中标记

Keep this value secret
复选框,以将 json 文件中的管理员私钥公开。


0
投票

除了之前的评论之外,您还可以将在google云控制台生成的.json文件放入Azure Devops库的Secure Files中,然后只需使用步骤下载安全文件

Step: download secure file

然后只需使用cmd脚本:

export GOOGLE_APPLICATION_CREDENTIALS=$(Agent.TempDirectory)/<your_sec_file_name>.json
© www.soinside.com 2019 - 2024. All rights reserved.