How to assign token value to a variable to use in next steps

Hi,

I’m running gcloud cli and I after I activate the service account I’m printing the token but how do I assign the token value to a variable to be used in subsequent steps like curl

gcloud auth activate-service-account --key-file=-
gcloud auth print-access-token

doing something like this dint work

TOKEN=gcloud auth print-access-token
echo TOKEN

TOKEN=$(gcloud auth print-access-token)
echo TOKEN

set TOKEN=gcloud auth print-access-token
echo TOKEN

TOKEN=$(tail -1)
echo TOKEN

Please help. Thanks in advance.

Hi @Dave,

Thank you for sharing your question on our forum.

You can persist variables to later steps by using syntax like the following:

- run:
    name: "Setup custom environment variables"
    command: echo 'export TEST="$(gcloud auth print-access-token)"' >> $BASH_ENV
- run:
    name: "Verify value of variable"
    command: echo $TEST

https://circleci.com/docs/env-vars#example-configuration-of-environment-variables

@aaronclark Thanks for your suggestion but unfortunately it dint work, please see the screenshot.