-
Notifications
You must be signed in to change notification settings - Fork 0
/
orb.yml
122 lines (104 loc) · 4.47 KB
/
orb.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
version: 2.1
description: |
Collection of jobs and commands to help manipulate the order of workflows, jobs in your pipeline.
display:
home_url: https://github.com/kelvintaywl/control-flow-orb
source_url: https://github.com/kelvintaywl/control-flow-orb
commands: {}
executors:
default:
docker:
- image: cimg/base:current
resource_class: small
jobs:
approve-workflow:
description: |
Looks for and approve an approval job in a specific workflow in this current pipeline.
Useful for forcing workflow XYZ to run only after workflow ABC.
Assumes the approval job is at the start of workflow XYZ in this case.
See the `sequential-workflow` example for more information.
NOTE: this requires a valid CircleCI API token, and assumes this is available via the $CIRCLE_TOKEN environment variable.
parameters:
workflow-name:
type: string
description: |
Name of the workflow to look up against.
Assumes the workflow name is unique.
Otherwise, it will look up the first workflow in this pipeline that matches this name.
job-name:
type: string
description: |
Name of the approval job in workflow to approve.
Assumes the job name is unique.
Otherwise, it will look up the first approval job in the workflow that matches this name.
executor: default
steps:
- run:
name: Find Pipeline ID
command: |
curl -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/workflow/${CIRCLE_WORKFLOW_ID}" > workflow.json
PIPELINE_ID=$(jq -r '.pipeline_id' workflow.json)
echo "Set current pipeline ID to PIPELINE_ID env var"
echo "export PIPELINE_ID='${PIPELINE_ID}'" >> $BASH_ENV
rm workflow.json
- run:
name: Find Workflow ID for << parameters.workflow-name >>
command: |
curl -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/pipeline/${PIPELINE_ID}/workflow" > workflows.json
WORKFLOW_ID=$(jq -r '.items | map(select(.name == "<< parameters.workflow-name >>")) | .[0].id' workflows.json)
echo "Set target workflow ID to WORKFLOW_ID env var"
echo "export WORKFLOW_ID='${WORKFLOW_ID}'" >> $BASH_ENV
rm workflows.json
- run:
name: Find Job ID for << parameters.job-name >>
command: |
curl -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/workflow/${WORKFLOW_ID}/job" > jobs.json
APPROVAL_JOB_ID=$(jq -r '.items | map(select(.name == "<< parameters.job-name >>" and .type == "approval")) | .[0].id' jobs.json)
echo "Set target approval job ID to APPROVAL_JOB_ID env var"
echo "export APPROVAL_JOB_ID='${APPROVAL_JOB_ID}'" >> $BASH_ENV
rm jobs.json
- run:
name: Approve << parameters.job-name >> job in << parameters.workflow-name >> workflow
command: |
curl -X POST -H "Circle-Token: $CIRCLE_TOKEN" "https://circleci.com/api/v2/workflow/${WORKFLOW_ID}/approve/${APPROVAL_JOB_ID}" | jq .
examples:
sequential-workflow:
description: |
Uses control-flow/approve-workflow job, an approval job to control the order between 2 workflows.
In this example, we want to run workflow bbb only after aaa.
We add an approval job (start) as the first job for workflow bbb.
We then add the control-flow/approve-workflow job as the final job in workflow aaa.
Essentially, workflow bbb is on-hold until workflow aaa approves the approval job in workflow bbb.
usage:
version: "2.1"
orbs:
flow: kelvintaywl/[email protected]
jobs:
noop:
docker:
- image: cimg/base:current
resource_class: small
steps:
- run: echo "noop"
workflows:
aaa:
jobs:
- noop:
name: build
- flow/approve-workflow:
workflow-name: bbb
job-name: start
requires:
- build
context:
# ASSUMPTION: this org context provides a $CIRCLE_TOKEN env var
# which contains a valid CircleCI API token as its value.
- circleci-api
bbb:
jobs:
- start:
type: approval
- noop:
name: deploy
requires:
- start