Search code examples
firebasegoogle-cloud-functionsfirebase-cli

What is the value of GCLOUD_PROJECT while running Firebase emulators?


I run firebase emulators:start to test my functions locally.
In my functions I use the GCLOUD_PROJECT environment variable to initialize firebase-admin accordingly.
What is the value of GCLOUD_PROJECT while running the emulators?


Solution

  • According to this pull request, GCLOUD_PROJECT should work like this:

    Manually tested:

    firebase emulators:exec --project foo 'env | grep GCLOUD' correctly outputs GCLOUD_PROJECT=foo
    firebase emulators:exec 'env | grep GCLOUD' gives nothing if firebase.json not present
    firebase emulators:exec 'env | grep GCLOUD' uses project id from firebase.json if available
    

    Also, in the documentation, it states:

    There are environment variables that are automatically populated in the functions runtime and in locally emulated functions, including:

    process.env.GCLOUD_PROJECT: Provides the Firebase project ID

    If it doesn't work the way you expect, then I suggest filing an issue on the same repo.