JSON string in curl

Hi all,
I’m trying to pass a json string to an api endpoint with curl from a pipeline. One of the values that I need to pass is the current git hash: I have this string but it’s not interpolating the $CIRCLE_SHA1 variable into the hash.

curl -H “Content-Type: application/json” -X POST -d ‘{“env”:"<< parameters.depenv >>", “hash”:"${CIRCLE_SHA1}"}’

I’ve tried removing the quotes from around ${CIRCLE_SHA1} as well as escaping them, neither works.
Thoughts?

Hi @devblueray! Thanks for stopping by the forum and welcome back!

Can you try switching the double-quotes and the single-quote, so that the double quote wraps the entire JSON, and the single quote wraps the key and value strings? For example:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/node:latest
    steps:
      - run: echo "{'hash':'${CIRCLE_SHA1}'}"

I wrapped the whole JSON in double quotes, and the ‘hash’ and ‘${CIRCLE_SHA1}’ in single quotes and was able to interpolate. Can you give that a spin?

Thank you!

1 Like