Firebase tools login from command line

对着背影说爱祢 提交于 2020-08-06 12:51:24

问题


I'm using Codeship to deploy a firebase app. In order to do so, I first need to login using the firebase login command. Problem is, I need to login in the browser and then return to the command line and perform the deployment. Is there an automated way to supply credentials to Firebase?

Cheers


回答1:


See wvm2008's answer for a more up to date version

One option would be to mint a token for the build server and pass it into the CLI with:

firebase --token <token>

You can also get a token from a system where you interactively logged in with:

firebase prefs:token

See this page for more options.




回答2:


The accepted answer is correct for the old version of firebase-tools, however this has been deprecated as of version 3. The new command to get the token is:

firebase login:ci

You should save this in some kind of environment variable, ideally, FIREBASE_TOKEN.

Then, with any command you intend to run via ci (i.e. deploy), you can run:

firebase [command] --token [FIREBASE_TOKEN]



回答3:


firebase login --no-localhost is what worked for me. You get the Authorisation code from browser which you need to paste into your terminal window.




回答4:


Answer: Environmental Variables.

Specifically, using a machine with a browser and firebase tools installed, run firebase login:ci --no-localhost and paste the resulting key from the firebase CLI tool into an Environmental Variable and name it FIREBASE_TOKEN (not $FIREBASE_TOKEN).

In your deployment, say

npm install -g firebase-tools
firebase deploy

Done. If you care about Why? Read on.

The firebase/firebase-tools repo README indicates the following regarding Usage with CI Systems.

The Firebase CLI requires a browser to complete authentication, but is fully compatible with CI and other headless environments.

On a machine with a browser, install the Firebase CLI. Run firebase login:ci to log in and print out a new access token (the current CLI session will not be affected).

NOTE: You actually want to type firebase login:ci --no-localhost

Store the output token in a secure but accessible way in your CI system. There are two ways to use this token when running Firebase commands:

Store the token as the environment variable FIREBASE_TOKEN and it will automatically be utilized. Run all commands with the --token <token> flag in your CI system.

  • 👉 NOTE: You MUST put your token in quotes IIF using the --token flag
  • 🔥 👉BIGGER NOTE Do NOT prefix your environment variable with $ or you will get a nonsensical error message below!!!

    Your CLI authentication needs to be updated to take advantage of new features. Please run firebase login --reauth

Error: Command requires authentication, please run firebase login

The order of precedence for token loading is flag, environment variable, active project.

👌 Recommendation is to use Environmental Variable so the secret token is not stored/visible in the logs.



来源:https://stackoverflow.com/questions/33939143/firebase-tools-login-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!