skip to Main Content

I have a command I execute on a pipeline :

firebase hosting:channel:deploy --only main --project test-project --config firebase.json test

This command apparently throw out those outputs =>
https://github.com/marketplace/actions/deploy-to-firebase-hosting

urls
The url(s) deployed to

expire_time
The time the deployed preview urls expire

details_url
A single URL that was deployed to

When I run it it goes basically with

$ firebase hosting:channel:deploy --only main --project test-project --config firebase.json test

=== Deploying to 'test-project'...

i  deploying hosting
i  hosting[test-project]: beginning deploy...
i  hosting[test-project]: found 497 files in dist/apps/main
+  hosting[test-project]: file upload complete
i  hosting[test-project]: finalizing version...
+  hosting[test-project]: version finalized
i  hosting[test-project]: releasing new version...
+  hosting[test-project]: release complete

+  Deploy complete!

Project Console: https://console.firebase.google.com/project/test-project/overview
Hosting URL: https://test-project.web.app
!  hosting:channel: Unable to add channel domain to Firebase Auth. Visit the Firebase Console at https://console.firebase.google.com/project/test-project/authentication/providers


!  hosting:channel: Unable to sync Firebase Auth state.

 +  hosting:channel: Channel URL (test-project): https://test-project--test-xj60axa8.web.app [expires 2022-11-01 12:22:04]

I would like to retrieve that last line, store it in a variable to reuse it in a future step of the pipeline.

I tried to do

 - RESULT=$(firebase hosting:channel:deploy --only main --project test-project --config firebase.json test)
 - echo "export PREVIEW_LINK=$RESULT" >> set_preview_link.sh

But this put the whole command output.

Is there a way to just get

hosting:channel: Channel URL (test-project): https://test-project--test-xj60axa8.web.app [expires 2022-11-01 12:22:04]

or even just the https://test-project--test-xj60axa8.web.app

2

Answers


  1. tail is useful for grabbing the last line of output.

    RESULT=$(firebase hosting:channel:deploy --only main --project test-project --config firebase.json test | tail -1)
    echo "$RESULT"
    

    Getting the URL specifically – depending on the possible outputs you could try to extract the column with something like awk or cut. Regular expressions can also work.

    RESULT=$(firebase hosting:channel:deploy --only main --project test-project --config firebase.json test | tail -1)
    url_regex='(https://[[:alnum:].-]+)'
    [[ "$RESULT" =~ $url_regex ]] && echo "${BASH_REMATCH[1]}"
    
    Login or Signup to reply.
  2. If your grep supports the -P flag.

    RESULT="$(firebase hosting:channel:deploy ... | grep -Po '(?<=Channel URL (test-project): )'.*'(?= [)')"
    

    Check the content of RESULT

    declare -p RESULT
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search