How to Deploy to Firebase Hosting With Bitbucket Pipelines
Install firebase-tools, point GOOGLE_APPLICATION_CREDENTIALS at a service account key, and run firebase deploy --only hosting.
Firebase Hosting deploys with the firebase CLI. Use a service account key (preferred over a CI token, which is deprecated) by exporting GOOGLE_APPLICATION_CREDENTIALS, then deploy only the hosting target.
Steps
- Create a service account with the Firebase Hosting Admin role and a JSON key.
- Store the key (base64) as the secured variable
FIREBASE_SA_KEY. - Export
GOOGLE_APPLICATION_CREDENTIALSto the decoded key file. firebase deploy --only hosting --project <id>.
Pipeline
bitbucket-pipelines.yml
image: node:20
pipelines:
branches:
main:
- step:
name: Deploy to Firebase Hosting
deployment: production
script:
- npm ci && npm run build
- npm i -g firebase-tools
- echo "$FIREBASE_SA_KEY" | base64 -d > /tmp/fb-key.json
- export GOOGLE_APPLICATION_CREDENTIALS=/tmp/fb-key.json
- firebase deploy --only hosting --project "$FIREBASE_PROJECT" --non-interactiveGotchas
- The legacy
FIREBASE_TOKEN/firebase login:ciflow is deprecated; use a service account. - Run the build before deploy so the
publicdirectory has the latest assets. --non-interactiveavoids the CLI hanging on a prompt in CI.
Related guides
How to Deploy to Netlify With Bitbucket PipelinesDeploy a site to Netlify from Bitbucket Pipelines with the netlify-cli, using an auth token and site id to pu…
How to Deploy to GCP Cloud Run With Bitbucket PipelinesDeploy a container to Google Cloud Run from Bitbucket Pipelines by activating a service account key and runni…