Access Firebase site id
Introduction
A short blog post to outline how to access the site identifier associated with a Firebase project.
Access Site Identifier
-
Accessing a list of sites
To access a list of sites you can use the following command
1firebase hosting:sites:list
-
The above command also supports exporting the list as json
1firebase hosting:sites:list --json
In the above the
defaultUrl
value represents the fully qualified site identifier
Access a specific Site Id
The firebase deploy command for hosting requires the site id to be specified.
In the example below, I prefix my sites with [ENV]-[PROJECT_ID]
e.g. dev/test/prod.
So the prefix I use is set to match that qualifier.
Amend the prefix to whatever you use for your site identifier.
To access this information from the above, you can use the following:
1SITE_ID=$(firebase hosting:sites:list --json | jq -r '.result.sites[] | select(.defaultUrl | startswith("https://dev-")) | .defaultUrl' | sed 's/https:\/\///' | sed 's/\.web\.app$//')
The above command does a couple of things:
- Gets a list of sites as JSON
- Uses JQ to access a value matching the prefix
https://dev-
- Removes the prefix
https://
- Removes the postfix
.web.app
The result is the matching site identifier which can then be used in the firebase deploy command e.g.:
1firebase deploy --only hosting:$SITE_ID