-
Notifications
You must be signed in to change notification settings - Fork 9
/
circleci.yaml
189 lines (171 loc) · 6.88 KB
/
circleci.yaml
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
systems:
circleci:
description: |
This system enables Honeydipper to integrate with `circleci`, so Honeydipper can
trigger pipelines in `circleci`.
meta:
configurations:
- name: circle_token
description: The token for making API calls to `circleci`.
- name: url
description: The base url of the API calls, defaults to :code:`https://circleci.com/api/v2`
- name: org
description: The default org name
data:
circle_token: _place_holder_
url: https://circleci.com/api/v2
org: _place_holder_
functions:
api:
driver: web
rawAction: request
parameters:
URL: '{{ .sysData.url }}/{{ .ctx.request_path }}'
header:
Circle-Token: $sysData.circle_token
Accept: application/json
Content-Type: application/json; charset=utf-8
description: >
This is a generic function to make a circleci API call with the configured token. This
function is meant to be used for defining other functions.
add_env_var:
target:
system: circleci
function: api
parameters:
URL: '{{ .sysData.url }}/project/{{ default "gh" .ctx.vcs }}/{{ coalesce .ctx.git_repo (print .sysData.org "/" .ctx.repo) }}/envvar'
method: POST
content:
name: $ctx.name
value: $ctx.value
description: >
Add env var to a project.
meta:
inputs:
- name: vcs
description: The VCS system integrated with this circle project, :code:`github` (default) or :code:`bitbucket`.
- name: git_repo
description: The repo that the env var is for, e.g. :code:`myorg/myrepo`, takes precedent over :code:`repo`.
- name: repo
description: The repo name that the env var is for, without the org, e.g. :code:`myrepo`
- name: name
description: Env var name
- name: value
description: Env var value
start_pipeline:
target:
system: circleci
function: api
parameters:
URL: '{{ .sysData.url }}/project/{{ default "gh" .ctx.vcs }}/{{ coalesce .ctx.git_repo (print .sysData.org "/" .ctx.repo) }}/pipeline'
method: POST
content:
branch: $ctx.git_branch
parameters: ':yaml:{{ set (default (dict) .ctx.pipeline_parameters) "via" (dict "honeydipper" "true") | toJson }}'
description: >
This function will trigger a pipeline in the given circleci project and branch.
meta:
inputs:
- name: vcs
description: The VCS system integrated with this circle project, :code:`github` (default) or :code:`bitbucket`.
- name: git_repo
description: The repo that the pipeline execution is for, e.g. :code:`myorg/myrepo`, takes precedent over :code:`repo`.
- name: repo
description: The repo name that the pipeline execution is for, without the org, e.g. :code:`myrepo`
- name: git_branch
description: The branch that the pipeline execution is on.
- name: pipeline_parameters
description: The parameters passed to the pipeline.
notes:
- See below for example
- example: |
---
rules:
- when:
driver: webhook
if_match:
url: /from_circle
export:
git_repo: $event.form.git_repo.0
git_branch: $event.form.git_branch.0
ci_workflow: $event.form.ci_workflow.0
do:
call_workflow: process_and_return_to_circle
workflows:
process_and_return_to_circle:
on_error: continue
steps:
- call_workflow: $ctx.ci_workflow
export_on_success:
pipeline_parameters:
deploy_success: "true"
- call_function: circleci.start_pipeline
- "Your :code:`circleci.yaml` might look like below"
- example: |
---
jobs:
version: 2
deploy:
unless: << pipeline.parameters.via.honeydipper >>
steps:
- ...
- run: curl <honeydipper webhook> # trigger workflow on honeydipper
continue_on_success:
when: << pipeline.parameters.deploy_success >>
steps:
- ...
- run: celebration
continue_on_failure:
when:
and:
- << pipeline.parameters.via.honeydipper >>
- not: << pipeline.parameters.deploy_success >>
steps:
- ...
- run: recovering
- run: # return error here
workflows:
version: 2
deploy:
jobs:
- deploy
- continue_on_success
- continue_on_failure
filters:
branches:
only: /^main$/
- |
For detailed information on conditional jobs and workflows please see the
`circleci support document <https://support.circleci.com/hc/en-us/articles/360043638052-Conditional-steps-in-jobs-and-conditional-workflows>`_.
workflows:
circleci_pipeline:
call_function: circleci.start_pipeline
description: This workflows wrap around the :code:`circleci.start_pipeline` function so it can be used as a hook.
meta:
notes:
- For example, below workflow uses a hook to invoke the pipeline.
- example: |
---
rules:
- when:
driver: webhook
if_match:
url: /from_circle
export:
git_repo: $event.form.git_repo.0
git_branch: $event.form.git_branch.0
ci_workflow: $event.form.ci_workflow.0
do:
call_workflow: process_and_return_to_circle
workflows:
process_and_return_to_circle:
with:
hooks:
on_exit+:
- circleci_pipeline
steps:
- call_workflow: $ctx.ci_workflow
export_on_success:
pipeline_parameters:
deploy_success: "true"