You can use github labels to control CircleCI build behavior.
Explanation
With Dynamic Config we can inspect the incoming payload to understand if it is related to any open PRs, and then take special action based on the applied labels.
version:2.1setup:truejobs:generate-config:executor:basesteps:- checkout- run:name:check tagscommand:| #
# Dynamic Config allows us to pass wholly distinct config files, depending on PR or non-PR flow.
#
if [[ -z ${CIRCLE_PULL_REQUEST} ]]; then
echo "no PR is open, use normal config"
FINAL_CONFIG_PATH=".circleci/continue.yml"
else
echo "Using PR pipeline. Call Github for current Labels:"
FINAL_CONFIG_PATH=".circleci/continue_pr.yml"
RESPONSE=`curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/issues/${CIRCLE_PULL_REQUEST##*/}/labels` | tee /tmp/response.txt
LABELS=`jq -c '.[] /tmp/response'
[ "$LABELS" ] || echo "No Labels defined"
fi
echo $LABELS | jq -s --arg continuation "$CIRCLE_CONTINUATION_KEY" \
--arg config "$(cat $FINAL_CONFIG_PATH)" \
'{"continuation-key": $continuation,
"configuration": $config,
"parameters": (if . == null then empty else ( map({ (.[].name): true}) | add ) end)
} | with_entries( select( .value != null ) ) ' | tee /tmp/continue-body.json
- run:name:continue API callcommand:| curl --request POST \
--url https://circleci.com/api/v2/pipeline/continue \
--header 'content-type: application/json' \
--data-binary @/tmp/continue-body.jsonworkflows:setup-workflow:jobs:- generate-configexecutors:base:docker:- image:cimg/base:stable
Continue Workflow - PR Only (continue_pr.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.1workflows:all_labels:jobs:- always_runbug_workflow:when:<< pipeline.parameters.bug >>jobs:- some_bug_job- always_runenhancement_workfow:when:<< pipeline.parameters.enhancement >>jobs:- some_enhancement_jobjobs:some_bug_job:executor:basesteps:- checkoutsome_enhancement_job:executor:basesteps:- checkoutalways_run:executor:basesteps:- checkoutexecutors:base:docker:- image:cimg/base:stable## The list of possible (finite) GH Tags is defined here as booleans#parameters:bug:type:booleandefault:falseenhancement:type:booleandefault:falsedocumentation:type:booleandefault:falsehelp wanted:type:booleandefault:falsegood first issue:type:booleandefault:falseinvalid:type:booleandefault:falsequestion:type:booleandefault:falsewontfix:type:booleandefault:false
Continue Workflow - Non PR (all pushes) (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.