CirleCI allowed parameters types include string and env_var_name which are both suitable to pass parameters intended to be used as environment variables, but serve different use cases.
Use Case: Passing values from a Dynamic Config (a.k.a. Setup Job) to downstream pipeline
Use Case: Capturing values passed from API or UI Trigger.
Use Case: Change the lookup name of variables used in job (i.e. reassign ACCESS_KEY_WEST, ACCESS_KEY_EAST)
Configuration (.circleci/config.yml)
This configuration consumes the parameter and declares it an Environment Variable in the job.
version:2.1parameters:circle_pr_number:type:stringdescription:Will be provided by setup jobdefault:""#empty on not PR jobscircle_pr_reponame:type:stringdescription:Will be provided by setup jobdefault:""#empty on not PR jobscircle_pr_username:type:stringdescription:Will be provided by setup jobdefault:""#empty on not PR jobscircle_pull_request:type:stringdescription:Will be provided by setup jobdefault:""#empty on not PR jobs# Single job will echos values# In continue job they will be parametersjobs:build:docker:- image:cimg/base:stableresource_class:smallsteps:- checkout- run:| # Just yse parameter anywhere in config
echo "The PR # is << pipeline.parameters.circle_pr_number >>"
# OR Set ENV VAR to value (for use in scripts, other commands)
export CIRCLE_PR_NUM=<< pipeline.parameters.circle_pr_number >>
# OR Save to $BASH_ENV to let subsequent steps use env var
echo "export CIRCLE_PR_NUM=<< pipeline.parameters.circle_pr_number >>" >> $BASH_ENV