How to assign value to parameter defined in workflow


I have defined a parameter like now in .config.yml

    type: string
    default: ""

now in one of the job i am trying to assign to some jq json filtered value to this parameter so that i can use this variable later

      - run:
          name: check
          command: |                   
            jq -r '' /tmp/output.json >> ${context_id} \
            echo ${context_id} \


#!/bin/bash -eo pipefail
jq -r '' /tmp/output.json >> ${context_id} \
echo ${context_id} \     
cat /tmp/output.json

/bin/bash: ${context_id}: ambiguous redirect

Exited with code exit status 1
CircleCI received exit code 1

Please help

Parameters are accessed via the format of << context_id >> and environment variables ${context_id}

Examples can be found here

Hi @onenessboy ,

As @rit1010 mentioned, parameters’ values are accessed using the syntax << parameters.parameter_name >>. However, it is not possible to assign a value directly to a parameter.

What you need to use, in this case, is the env_var_name parameter type. You can then assign a value to the corresponding environment variable, and it’ll be passed on to the env_var_name parameter that refers to it.

The parameter value will then have to be accessed using the following syntax:
${<< parameters.parameter_name >>}

Hi @yannCI,

I tried this syntax: ${<< parameters.parameter_name >>} to access Circleci built-in environment variable: pipeline.number:
echo “pipeline.number: ${<<pipeline.number>>}”

I got this error: /bin/bash: line 10: pipeline.number: ${<<pipeline.number>>}: bad substitution

Yes you will get an error as the text the circleci parser replaces an instance of <<something.something>> that it recognizes with its real value before the shell is executed so

so if << pipeline.number>> is recognized as having the value of 10 by the circleci parser

What is being executed by bash in your example will be echo “pipeline.number: ${10}”

All you should need to enter is echo “pipeline.number: <<pipeline.number>>”

If you are seeing an error from within bash it is normally easy to debug as the pipeline report on the dashboard will show the exact shell script that is to be executed after the circleci parser has made its modifications/substitutions.

@rit1010, thanks for your response! If I use this: echo “pipeline.number: <<pipeline.number>>”, I don’t get any error. But it does not interpolate the variable. It just prints: pipeline.number

I posted more to your other thread regarding that.

Sorry, which other thread? I created only this one. Could you please post here?

Thank you!

Ok, I see the other thread now, will respond there