If using Dynamic Config, you will realize that some PR based variables we capture for you (CIRCLE_PR_NUMBER, etc) are present in the initial setup job, but not the continue job.
This gist shows how to capture & pass those values as parameters to the continue workflow as well!
version:2.1# Mark config as setup, and declare continuation orbsetup:trueorbs:continuation:circleci/continuation@0.1.2# Single job will pull current vars, and pass as JSON to continue job.# TIP: A single job named 'build' does not need a `workflows` stanza!jobs:build:docker:- image:cimg/base:stableresource_class:smallsteps:- checkout# Run steps can be any shell - including PYTHON!! # Use python to parse list of desired values, and create JSON payload.- run:name:generate jsonshell:/usr/bin/env python3command:|+ import os
import json
env_var_to_save = [
"CIRCLE_PR_NUMBER",
"CIRCLE_PR_REPONAME",
"CIRCLE_PR_USERNAME",
"CIRCLE_PULL_REQUEST"
]
pipeline_vars = {}
for var in env_var_to_save:
if os.environ.get(var) != None:
pipeline_vars[var.lower()] = os.environ[var]
else:
pipeline_vars[var.lower()] = ""
pipeline_vars['IS_PR'] = len(pipeline_vars['circle_pull_request']) > 0
with open('params.json', 'w') as fp:
fp.write(json.dumps(pipeline_vars))# Pass the generated JSON parameters and alternate config.yml to run- continuation/continue:configuration_path:config_continue.ymlparameters:params.json
Continue Workflow (config_continue.yml)
This single continue job shows the various ways you can access the passed parameters. Note their declaration and default value of empty string. This allows not PR jobs to run when those values were not passed.
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