I'm trying to extract the value of a HTTP request in a GitHub action and then use that value in another step.
This is the current code:
- run: call some https endpoint
and that returns to the console output:
{
"authorizationToken": "<snip>",
"expiration": "2021-02-26T18:18:38+00:00"
}
and I'm trying to extract the authorizationToken value and then use it in the next step, like
-name: Get auth token
run: call some https endpoint
-name: set something which uses the token
run: set blah --token $token_from_previous_step
~ - run: call some https endpoint | echo "jq '.authorizationToken'"~
which errors with:
jq '.authorizationToken'
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
BrokenPipeError: [Errno 32] Broken pipe
I'm now able to extract the key/value .. but not sure how to set it as an environment variable, to be used in other steps.
This works:
- run: call some https endpoint > at.json
- run: jq '.authorizationToken' at.json
so that get the json output from that https endpoint result and saves the result into a file called at.json (which is the json text, above).
Next, I then run the jq command, extracting the authorizationToken value. which works!
Now I need to set this value as a env-var. Reading the docs on this, it looks like it can be done, but I'm not sure how to call jq and set the key/value into an env-var.
I feel like I need to do something like this:
- run: echo "AUTH_TOKEN=run the jq command here" >> $GITHUB_ENV
Something like this (which totally fails):
- run: echo "AUTH_TOKEN=${{ jq '.authorizationToken' at.json }}" >> $GITHUB_ENV