c14ea6c47e8ebfa57638a191701c0d3ddba211bc
[releng.git] / jjb / releng-macros.yaml
1 # OLD Releng macros
2
3 - parameter:
4     name: project-parameter
5     parameters:
6         - string:
7             name: PROJECT
8             default: '{project}'
9             description: "JJB configured PROJECT parameter to identify an opnfv Gerrit project"
10         - string:
11             name: GS_BASE
12             default: artifacts.opnfv.org/$PROJECT
13             description: "URL to Google Storage."
14         - string:
15             name: GS_BASE_PROXY
16             default: build.opnfv.org/artifacts/$PROJECT
17             description: "URL to Google Storage proxy"
18
19 - parameter:
20     name: gerrit-parameter
21     parameters:
22         - string:
23             name: GERRIT_BRANCH
24             default: '{branch}'
25             description: "JJB configured GERRIT_BRANCH parameter"
26
27 - scm:
28     name: git-scm
29     scm:
30         - git:
31             credentials-id: '{credentials-id}'
32             url: '$GIT_BASE'
33             refspec: ''
34             branches:
35                 - 'origin/{branch}'
36             skip-tag: true
37             wipe-workspace: true
38
39 - scm:
40     name: gerrit-trigger-scm
41     scm:
42         - git:
43             credentials-id: '{credentials-id}'
44             url: '$GIT_BASE'
45             refspec: '{refspec}'
46             branches:
47                 - 'origin/$GERRIT_BRANCH'
48             skip-tag: true
49             choosing-strategy: '{choosing-strategy}'
50
51 - wrapper:
52     name: build-timeout
53     wrappers:
54         - timeout:
55             type: absolute
56             timeout: 360
57             fail: true
58
59 - trigger:
60     name: 'daily-trigger-disabled'
61     triggers:
62         - timed: ''
63
64 - trigger:
65     name: 'weekly-trigger-disabled'
66     triggers:
67         - timed: ''
68
69 - trigger:
70     name: 'brahmaputra-trigger-daily-enabled'
71     triggers:
72         - timed: '0 2 * * *'
73
74 - trigger:
75     name: gerrit-trigger-patch-submitted
76     triggers:
77         - gerrit:
78             server-name: 'gerrit.opnfv.org'
79             trigger-on:
80                 - patchset-created-event:
81                     exclude-drafts: 'false'
82                     exclude-trivial-rebase: 'false'
83                     exclude-no-code-change: 'false'
84                 - draft-published-event
85                 - comment-added-contains-event:
86                     comment-contains-value: 'recheck'
87             projects:
88               - project-compare-type: 'ANT'
89                 project-pattern: '{name}'
90                 branches:
91                   - branch-compare-type: 'ANT'
92                     branch-pattern: '**/{branch}'
93
94 - trigger:
95     name: gerrit-trigger-patch-merged
96     triggers:
97         - gerrit:
98             server-name: 'gerrit.opnfv.org'
99             trigger-on:
100                 - change-merged-event
101                 - comment-added-contains-event:
102                     comment-contains-value: 'remerge'
103             projects:
104               - project-compare-type: 'ANT'
105                 project-pattern: '{name}'
106                 branches:
107                   - branch-compare-type: 'ANT'
108                     branch-pattern: '**/{branch}'
109
110 - publisher:
111     name: archive-artifacts
112     publishers:
113         - archive:
114             artifacts: '{artifacts}'
115             allow-empty: true
116             fingerprint: true
117             latest-only: true
118
119 - publisher:
120     name: email-notification
121     publishers:
122         - email-ext:
123             recipients: 'jenkins@lists.opnfv.org'
124             reply-to:
125             content-type: default
126             subject: '{email-prefix} $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!'
127             body: |
128                 $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
129
130                 Check console output at $BUILD_URL to view the results.
131             unstable: true
132             fixed: true
133             send-to:
134                 - developers
135                 - recipients
136
137 - publisher:
138         name: jacoco-report
139         publishers:
140             - jacoco:
141                 exec-pattern: "**/**.exec"
142                 class-pattern: "**/classes"
143                 source-pattern: "**/src/main/java"
144                 exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**"
145                 status-update: true
146                 targets:
147                   - branch:
148                       healthy: 10
149                       unhealthy: 20
150                   - method:
151                       healthy: 50
152                       unhealthy: 40
153
154
155 - builder:
156     name: test-macro
157     builders:
158         - shell: 'echo testing macro "test-macro"'
159
160 - builder:
161     name: wipe-org-opendaylight-repo
162     builders:
163         - shell: 'if [ -d /tmp/r/org/opendaylight ]; then rm -rf /tmp/r/org/opendaylight; fi'
164
165 - builder:
166     name: jacoco-nojava-workaround
167     builders:
168         - shell: 'mkdir -p $WORKSPACE/target/classes'
169
170
171 # New Releng macros
172
173 - builder:
174     name: build-html-and-pdf-docs-output
175     builders:
176         - shell: |
177             #!/bin/bash
178             set -o errexit
179             set -o xtrace
180             export PATH=$PATH:/usr/local/bin/
181             git clone ssh://gerrit.opnfv.org:29418/opnfvdocs docs_build/_opnfvdocs
182             GERRIT_COMMENT=gerrit_comment.txt ./docs_build/_opnfvdocs/scripts/docs-build.sh
183
184 - builder:
185     name: upload-under-review-docs-to-opnfv-artifacts
186     builders:
187         - shell: |
188             #!/bin/bash
189             set -o errexit
190             set -o pipefail
191             set -o xtrace
192             export PATH=$PATH:/usr/local/bin/
193
194             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
195             [[ -d docs_output ]] || exit 0
196
197             echo
198             echo "###########################"
199             echo "UPLOADING DOCS UNDER REVIEW"
200             echo "###########################"
201             echo
202
203             gs_base="artifacts.opnfv.org/$PROJECT/review"
204             gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
205             local_path="upload/$GERRIT_CHANGE_NUMBER"
206
207             mkdir -p upload
208             mv docs_output "$local_path"
209             gsutil -m cp -r "$local_path" "gs://$gs_base"
210
211             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
212                 gsutil -m setmeta \
213                     -h "Content-Type:text/html" \
214                     -h "Cache-Control:private, max-age=0, no-transform" \
215                     "gs://$gs_path"/**.html
216             fi
217
218             echo "Document link(s):" >> gerrit_comment.txt
219             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
220                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
221
222 - builder:
223     name: upload-generated-docs-to-opnfv-artifacts
224     builders:
225         - shell: |
226             #!/bin/bash
227             set -o errexit
228             set -o pipefail
229             set -o xtrace
230             export PATH=$PATH:/usr/local/bin/
231
232             [[ -d docs_output ]] || exit 0
233
234             echo
235             echo "########################"
236             echo "UPLOADING GENERATED DOCS"
237             echo "########################"
238             echo
239
240             gs_path="$GS_URL/docs"
241             local_path="upload/docs"
242
243             mkdir -p upload
244             mv docs_output "$local_path"
245             gsutil -m cp -r "$local_path" "gs://$GS_URL"
246
247             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
248                 gsutil -m setmeta \
249                     -h "Content-Type:text/html" \
250                     -h "Cache-Control:private, max-age=0, no-transform" \
251                     "gs://$gs_path"/**.html
252             fi
253
254             echo "Document link(s):" >> gerrit_comment.txt
255             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
256                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
257
258 - builder:
259     name: report-docs-build-result-to-gerrit
260     builders:
261         - shell: |
262             #!/bin/bash
263             set -o errexit
264             set -o pipefail
265             set -o xtrace
266             export PATH=$PATH:/usr/local/bin/
267             if [[ -e gerrit_comment.txt ]] ; then
268                 echo
269                 echo "posting review comment to gerrit..."
270                 echo
271                 cat gerrit_comment.txt
272                 echo
273                 ssh -p 29418 gerrit.opnfv.org \
274                     "gerrit review -p $GERRIT_PROJECT \
275                      -m '$(cat gerrit_comment.txt)' \
276                      $GERRIT_PATCHSET_REVISION \
277                      --notify NONE"
278             fi
279
280 - builder:
281     name: remove-old-docs-from-opnfv-artifacts
282     builders:
283         - shell: |
284             #!/bin/bash
285             set -o errexit
286             set -o pipefail
287             set -o xtrace
288             export PATH=$PATH:/usr/local/bin/
289
290             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
291
292             gs_path="artifacts.opnfv.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
293
294             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
295                 echo
296                 echo "Deleting Out-of-dated Documents..."
297                 gsutil -m rm -r "gs://$gs_path"
298             fi
299             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
300
301             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
302                 echo
303                 echo "Deleting Out-of-dated Documents..."
304                 gsutil -m rm -r "gs://$gs_path"
305             fi
306
307 - builder:
308     name: build-and-upload-artifacts-json-api
309     builders:
310         - shell: |
311             #!/bin/bash
312             set -o errexit
313             set -o pipefail
314             export PATH=$PATH:/usr/local/bin/
315
316             virtualenv -p python2.7 $WORKSPACE/releng_artifacts
317             source $WORKSPACE/releng_artifacts/bin/activate
318
319             # install python packages
320             pip install google-api-python-client
321
322             # generate and upload index file
323             echo "Generating Artifacts API ..."
324             python $WORKSPACE/utils/opnfv-artifacts.py > index.json
325             gsutil cp index.json gs://artifacts.opnfv.org/index.json
326
327             deactivate
328
329 - builder:
330     name: lint-python-code
331     builders:
332         - shell: |
333             #!/bin/bash
334             set -o errexit
335             set -o pipefail
336             set -o xtrace
337             export PATH=$PATH:/usr/local/bin/
338
339             virtualenv -p python2.7 $WORKSPACE/releng_flake8
340             source $WORKSPACE/releng_flake8/bin/activate
341
342             # install python packages
343             pip install "flake8==2.6.2"
344
345             # generate and upload lint log
346             echo "Running flake8 code on $PROJECT ..."
347
348             # Get number of flake8 violations. If none, this will be an
349             # empty string: ""
350             FLAKE_COUNT="$(find . \
351                 -path './releng_flake8' -prune -o \
352                 -path './.tox' -prune -o \
353                 -type f -name "*.py" -print | \
354                 xargs flake8 --exit-zero -qq --count 2>&1)"
355
356             # Ensure we start with a clean environment
357             rm -f lint.log
358
359             if [ ! -z $FLAKE_COUNT ]; then
360               echo "Flake8 Violations: $FLAKE_COUNT" > lint.log
361               find . \
362                   -path './releng_flake8' -prune -o \
363                   -path './.tox' -prune -o \
364                   -type f -name "*.py" -print | \
365                   xargs flake8 --exit-zero --first >> violation.log
366               SHOWN=$(wc -l violation.log | cut -d' ' -f1)
367               echo -e "First $SHOWN shown\n---" >> lint.log
368               cat violation.log >> lint.log
369               sed -r -i '4,$s/^/ /g' lint.log
370               rm violation.log
371             fi
372
373             deactivate
374
375 - builder:
376     name: report-lint-result-to-gerrit
377     builders:
378         - shell: |
379             #!/bin/bash
380             set -o errexit
381             set -o pipefail
382             set -o xtrace
383             export PATH=$PATH:/usr/local/bin/
384
385             # If no violations were found, no lint log will exist.
386             if [[ -e lint.log ]] ; then
387                 echo -e "\nposting linting report to gerrit...\n"
388
389                 cat lint.log
390                 echo
391
392                 ssh -p 29418 gerrit.opnfv.org \
393                     "gerrit review -p $GERRIT_PROJECT \
394                      -m \"$(cat lint.log)\" \
395                      $GERRIT_PATCHSET_REVISION \
396                      --notify NONE"
397
398                 exit 1
399             fi
400
401 - builder:
402     name: upload-review-docs
403     builders:
404         - build-html-and-pdf-docs-output
405         - upload-under-review-docs-to-opnfv-artifacts
406         - report-docs-build-result-to-gerrit
407
408 - builder:
409     name: upload-merged-docs
410     builders:
411         - build-html-and-pdf-docs-output
412         - upload-generated-docs-to-opnfv-artifacts
413         - report-docs-build-result-to-gerrit
414         - remove-old-docs-from-opnfv-artifacts
415
416 - builder:
417     name: check-bash-syntax
418     builders:
419         - shell: "find . -name '*.sh' | xargs bash -n"