在非交互式环境中验证和使用 Firebase

Authenticate and use Firebase in non-interactive environments

我使用 Android 移动应用程序,源代码在 Azure 中维护。我想根据要求自动执行构建过程并在 Firebase App Distribution 中上传 .apk 文件。

我使用 Azure Pipeline to automate the build process. Am using .yml 文件来自动化该过程。能够生成 .apk 文件。我需要将其上传到 Firebase。

关注了几个博客,最后得到了下面需要在我的 .yml 文件中编写的代码

- script: |
    cd functions
    npm init --yes
    npm install -g firebase-tools
    npm install
    firebase login --interactive
    firebase appdistribution:distribute --app APP_ID --release-notes "My first distribution" --testers "xyzh@gmail.com" $(build.artifactStagingDirectory)$(Build.ArtifactStagingDirectory)/android-devops.apk
  displayName: 'npm install and deploy'

有了这个,无法登录到 firebase,因为在 运行 上没有交互。它由 Azure 在 运行 完成作业时完全自动化。如果我在命令提示符下使用这些命令,它会打开 firebase 登录页面并在登录时获得身份验证。之后 appdistribution:distribute 命令成功将应用程序上传到 Firebase。但是我需要在 Azure Devops Pipeline 中自动化这个过程,那里不会有交互。

请先尝试生成身份验证令牌,然后使用以下两个选项之一:

  • 将令牌存储为环境变量FIREBASE_TOKEN。您的 系统会自动使用令牌。
  • 运行 所有 firebase 命令在你的 CI 中带有 --token 标志 系统.

https://firebase.google.com/docs/cli/#command_reference

我刚用过 firebase login:ci --interactive,对我来说效果很好