Search code examples
firebase-cli

Print hosting default URL (or channel URL) with Firebase CLI


The Firebase CLI tool can show me the default URLs of the hosting site(s) of a project in a human-readable format:

$ firebase hosting:sites:list

Sites for project <my-app>

┌──────────────────┬──────────────────────────────────┬─────────────────┐
│ Site ID          │ Default URL                      │ App ID (if set) │
├──────────────────┼──────────────────────────────────┼─────────────────┤
│ my-app           │ https://<my-app>.web.app         │ --              │
└──────────────────┴──────────────────────────────────┴─────────────────┘

If I have multiple channels, it can also show me the URLs for each channel on a given site:

$ firebase hosting:channel:list

Channels for site <my-app>

┌────────────┬─────────────────────┬──────────────────────────────────┬─────────────┐
│ Channel ID │ Last Release Time   │ URL                              │ Expire Time │
├────────────┼─────────────────────┼──────────────────────────────────┼─────────────┤
│ live       │ 2022-10-27 15:06:54 │ https://<my-app>.web.app         │ never       │
└────────────┴─────────────────────┴──────────────────────────────────┴─────────────┘

But how do I print only the URL of a channel, for use in a shell script? (Without resorting to regexes.)


Solution

  • You can use a --json argument.

    Combined with jq, you can retrieve a specific URL.

    Example with live channel:

    $ firebase hosting:channel:list --json |\
    jq '.result.channels[]|select(.name|contains("live")) | .url'