0

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

Bobby
  • 4,372
  • 8
  • 47
  • 103

2 Answers2

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]}"
tjm3772
  • 2,346
  • 2
  • 10
  • I see, so no way to get output independently ? I will try tail and update the answer thanks ! – Bobby Oct 25 '22 at 03:50
  • If by "independently" you mean you want firebase to only output that portion then I'm not sure, I am not familiar with that tool. Someone who knows it better might know an option to change the output it provides. – tjm3772 Oct 25 '22 at 03:53
  • `tail -1` is obsolete (but still usually supported in order to not break old scripts). Use `tail -n 1` instead. – user1934428 Oct 25 '22 at 04:56
  • @Bobby: I don't understand what you mean by _get output independently_, and there is nothing in your question which would explain this point. If this is a new problem, ask a new question for it. – user1934428 Oct 25 '22 at 05:01
  • they say they output 3 different things. I would like to retrieve only one output out of the tree. This is what I mean. – Bobby Oct 25 '22 at 05:18
1

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
Jetchisel
  • 7,493
  • 2
  • 19
  • 18