-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathstep.yaml
261 lines (260 loc) · 9.77 KB
/
step.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
version: '1.0'
kind: step-type
metadata:
name: codefresh-run
title: Run a Codefresh pipeline
version: 1.5.3
isPublic: true
description: Run a Codefresh pipeline by ID or name and attach the created build logs.
sources:
- 'https://github.com/codefresh-io/steps/tree/master/graduated/codefresh-run'
stage: graduated
maintainers:
- name: Itai Gendler
email: [email protected]
categories:
- featured
official: true
tags: []
icon:
type: svg
url: >-
https://cdn.jsdelivr.net/gh/codefresh-io/steps/graduated/codefresh-run/icon-1.svg
background: '#C7DCFF'
examples:
- description: example-1
workflow:
codefresh-run:
title: Run a codefresh pipeline
type: codefresh-run
arguments:
PIPELINE_ID: project-name/pip_name
TRIGGER_ID: trigger_id
BRANCH: '${{CF_BRANCH}}'
SHA: '${{CF_REVISION}}'
VARIABLE:
- key1=val1
- key2=val2
- key3=val3
created_at: '2019-12-24T15:42:47.178Z'
updated_at: '2019-12-24T15:42:47.178Z'
latest: true
id: 5e0231f76e1ebe58d5d37a37
spec:
arguments: |-
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"patterns": [],
"required": [
"PIPELINE_ID"
],
"properties": {
"IMAGE_TAG": {
"type": "string",
"description": "Custom image of codefresh-run step",
"examples": ["latest-debian"],
"default": "0.84.7"
},
"PIPELINE_ID": {
"type": "string",
"description": "Name or ID of pipeline to run. In the UI, select Pipelines. Click pipeline name, then select Settings, and get the Name and ID."
},
"TRIGGER_ID": {
"type": "string",
"description": "Name or ID of trigger for specified pipeline. Mandatory when BRANCH or SHA are defined. In the UI, select Pipelines. Click pipeline name, then select Workflows > Triggers. Click Edit and get the Name. ",
"default": ""
},
"BRANCH": {
"type": "string",
"description": "Branch for which to run the pipeline. When defined, TRIGGER_ID must also be defined.",
"examples": ["master"],
"default": ""
},
"SHA": {
"type": "string",
"description": "Git commit hash. When defined, TRIGGER_ID must also be defined.",
"examples": ["c777d850ff67969cb4eb9e041d7edeb367705e12"],
"default": ""
},
"NO_CACHE": {
"type": "boolean",
"description": "Ignore cached images.",
"default": false
},
"NO_CF_CACHE": {
"type": "boolean",
"description": "Ignore Codefresh cache optimizations.",
"default": false
},
"ENABLE_NOTIFICATIONS": {
"type": "boolean",
"description": "Send email notifications on pipeline build status.",
"default": false
},
"RESET_VOLUME": {
"type": "boolean",
"description": "Reset pipeline cached volume.",
"default": false
},
"RUNTIME_NAME": {
"type": "string",
"description": "Runtime environment to run the pipeline.",
"examples": ["my-runtime-name"],
"default": ""
},
"PACK_NAME": {
"type": "string",
"description": "Resources size (small, medium or large).",
"default": ""
},
"DETACH": {
"type": "boolean",
"description": "Run child pipeline and export the child pipeline's build ID to the $BUILD_ID variable without waiting for the pipeline to complete.",
"default": false
},
"FOLLOW_LOGS": {
"type": "boolean",
"description": "Run pipeline and follow its logs.",
"default": true
},
"CONTEXT": {
"type": "array",
"items": {
"type": "string"
},
"description": "Run pipeline with execution contexts.",
"examples": ["git-context-1"],
"default": []
},
"VARIABLE": {
"type": "array",
"items": {
"type": "string"
},
"description": "Set build variables.",
"examples": ["key=val"],
"default": []
},
"VARIABLE_FILE": {
"type": "string",
"description": "Import build variables from a file.",
"examples": ["/codefresh/volume/my-repo/var_file_example.yml"],
"default": ""
},
"TIMEOUT_MINS": {
"type": "string",
"description": "Timeout in minutes after which to consider pipeline build as failed.",
"examples": ["33.3", "45"],
"default": "45"
},
"TERMINATE_ON_TIMEOUT": {
"type": "boolean",
"description": "Terminate build if timeout reached",
"default": false
},
"ONLY": {
"type": "array",
"items": {
"type": "string"
},
"description": "Run only specifc steps defined.",
"examples": ["step1", "step2"],
"default": []
},
"SKIP": {
"type": "array",
"items": {
"type": "string"
},
"description": "Skip the specifc steps defined.",
"examples": ["step1", "step2"],
"default": []
},
"YAML": {
"type": "string",
"description": "Path to pipeline's yaml to be used as override for this execution.",
"default": ""
}
}
}
delimiters:
left: '[['
right: ']]'
stepsTemplate: |-
first:
image: quay.io/codefresh/cli:[[.Arguments.IMAGE_TAG]]
commands:
[[- $cmd := (printf "codefresh run \"%s\" -d" .Arguments.PIPELINE_ID ) -]]
[[ if .Arguments.TRIGGER_ID ]]
[[- $cmd = (printf "%s -t %s" $cmd .Arguments.TRIGGER_ID) -]]
[[- end -]]
[[ if .Arguments.BRANCH ]]
[[- $cmd = (printf "%s -b %s" $cmd .Arguments.BRANCH) -]]
[[- end -]]
[[ if .Arguments.SHA ]]
[[- $cmd = (printf "%s -s %s" $cmd .Arguments.SHA) -]]
[[- end -]]
[[ if .Arguments.NO_CACHE ]]
[[- $cmd = (printf "%s --no-cache" $cmd) -]]
[[- end -]]
[[ if .Arguments.NO_CF_CACHE ]]
[[- $cmd = (printf "%s --no-cf-cache" $cmd) -]]
[[- end -]]
[[ if .Arguments.ENABLE_NOTIFICATIONS ]]
[[- $cmd = (printf "%s --enable-notifications" $cmd) -]]
[[- end -]]
[[ if .Arguments.RESET_VOLUME ]]
[[- $cmd = (printf "%s --reset-volume" $cmd) -]]
[[- end -]]
[[ if .Arguments.RUNTIME_NAME ]]
[[- $cmd = (printf "%s --runtime-name %s" $cmd .Arguments.RUNTIME_NAME) -]]
[[- end -]]
[[ if .Arguments.PACK_NAME ]]
[[- $cmd = (printf "%s --pack-name %s" $cmd .Arguments.PACK_NAME) -]]
[[- end -]]
[[ range .Arguments.VARIABLE ]]
[[- $cmd = (printf "%s --variable %s" $cmd .) -]]
[[- end -]]
[[ if .Arguments.VARIABLE_FILE ]]
[[- $cmd = (printf "%s --var-file %s" $cmd .Arguments.VARIABLE_FILE) -]]
[[- end -]]
[[ range .Arguments.CONTEXT ]]
[[- $cmd = (printf "%s --context %s" $cmd .) -]]
[[- end -]]
[[ range .Arguments.ONLY ]]
[[- $cmd = (printf "%s --only %s" $cmd .) -]]
[[- end -]]
[[ range .Arguments.SKIP ]]
[[- $cmd = (printf "%s --skip %s" $cmd .) -]]
[[- end ]]
[[ if .Arguments.YAML ]]
[[- $cmd = (printf "%s --yaml %s" $cmd .Arguments.YAML) -]]
[[- end -]]
[[/* Multiline string is required to support usage of 'colon' (:) character in the string. For example in the pipeline name. */]]
[[/* Otherwise after template render there is a chance to have an object instead of a string. */]]
- >-
CLI_OUTPUT=$([[ $cmd ]]) &&
export BUILD_ID=$(echo "$CLI_OUTPUT" | tail -n 1); if [ -z "$BUILD_ID" ]; then exit 1; fi
- cf_export first_CF_OUTPUT_URL="${{CF_URL}}/build/$BUILD_ID"
- cf_export BUILD_ID
[[- if eq .Arguments.DETACH false ]]
second:
name: step1
image: quay.io/codefresh/cli:[[.Arguments.IMAGE_TAG]]
commands:
- export BUILD_ID=${{steps.first.output.BUILD_ID}}
[[- if eq .Arguments.FOLLOW_LOGS true ]]
- echo "Retrieving logs for build $BUILD_ID"
- codefresh logs -f --no-timestamps $BUILD_ID
[[- end ]]
- >-
codefresh wait --verbose $BUILD_ID --timeout [[(printf "%s" .Arguments.TIMEOUT_MINS)]]
[[- if eq .Arguments.TERMINATE_ON_TIMEOUT true ]]
|| (echo "TERMINATE_ON_TIMEOUT was set to true, sending termination request" &&
codefresh terminate $BUILD_ID &&
exit 1)
[[- end ]]
[[- end -]]