Created
June 28, 2021 18:55
-
-
Save rattrayalex/d86b4c98bf70193e30f88dab2904da14 to your computer and use it in GitHub Desktop.
Running different CircleCI workflows based on environment variables created in a shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
setup: true | |
orbs: | |
continuation: circleci/[email protected] | |
jobs: | |
determine-workflow: | |
machine: true | |
steps: | |
- checkout | |
- run: | |
name: Generate parameters for main job | |
shell: /usr/bin/env bash -eo pipefail | |
command: | | |
env | |
export COMMIT_MESSAGES="$(git log stage.. --pretty=format:%B)"; | |
if [[ "$CIRCLE_TAG" =~ ^v[0-9.]+$ ]]; then | |
WORKFLOW='prod' | |
elif [[ "$CIRCLE_BRANCH" =~ ^stage ]]; then | |
WORKFLOW='stage' | |
elif [[ "$COMMIT_MESSAGES" =~ deploy.demo ]]; then | |
WORKFLOW='demo' | |
else | |
WORKFLOW='dev' | |
fi | |
cat \<<- EOF > /home/circleci/main_parameters.json | |
{ | |
"workflow": "$WORKFLOW" | |
} | |
EOF | |
cat /home/circleci/main_parameters.json | |
- continuation/continue: | |
configuration_path: .circleci/main.yml | |
parameters: /home/circleci/main_parameters.json | |
workflows: | |
version: 2 | |
setup: | |
jobs: | |
- determine-workflow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
setup: false | |
parameters: | |
workflow: | |
type: enum | |
enum: | |
- prod | |
- stage | |
- demo | |
- dev | |
default: dev | |
jobs: | |
# ... | |
workflows: | |
version: 2 | |
stage: | |
when: | |
equal: [stage, << pipeline.parameters.workflow >>] | |
jobs: # ... | |
prod: | |
when: | |
equal: [prod, << pipeline.parameters.workflow >>] | |
jobs: # ... | |
dev: | |
when: | |
or: | |
- equal: [dev, << pipeline.parameters.workflow >>] | |
- equal: [demo, << pipeline.parameters.workflow >>] | |
jobs: # ... | |
demo: | |
when: | |
equal: [demo, << pipeline.parameters.workflow >>] | |
jobs: # ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment