17

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

atardadi
  • 429
  • 2
  • 5
  • 14

4 Answers4

31

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.

Philippe Fanaro
  • 6,148
  • 6
  • 38
  • 76
tw56
  • 311
  • 3
  • 2
19

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]
wvm2008
  • 2,864
  • 4
  • 21
  • 25
  • 1
    If you use the environmental variable FIREBASE_TOKEN then all you need is firebase [command] and it automatically used, unless you've specified the --token flag which is not preferred as it displays the secret key in the logs. (see my answr). Dont prefix env var with $!!!! – Ronnie Royston May 16 '17 at 00:58
6

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 login:ci

See this page for more options.

Elron
  • 1,235
  • 1
  • 13
  • 26
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
5

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.

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91