write environment variable to JSON in pipelines.yml

Micha Roon April 7, 2019

my `bitbucket-pipelines.yml` file contains the following lines:

default:
- step:
caches:
- node
script:
- echo "{\"infuraKey\": \"$INFURA_KEY\"}" > infura-key.json
- npm i ganache-core
- npm i
- npm test

the line with `echo "...` generates a validation error. What is the correct syntax?

1 answer

1 accepted

3 votes
Answer accepted
Philip Hodder
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 11, 2019

Hi Micha,

YAML parses the ': ' (colon immediately followed by a space) as a map. Which breaks the parsing we expect (a string).

To working around this, you can either

Place the entire command into a string:

default:
- step:
caches:
- node
script:
- 'echo "{\"infuraKey\": \"$INFURA_KEY\"}" > infura-key.json'
- npm i ganache-core
- npm i
- npm test

Or, place the command onto a separate line:

default:
- step:
caches:
- node
script:
- |
echo "{\"infuraKey\": \"$INFURA_KEY\"}" > infura-key.json
- npm i ganache-core
- npm i
- npm test

Thanks,

Phil

Simon Bromley July 2, 2020

Thanks - this was puzzling the hell out of me why the colon was causing a YAML syntax error

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events