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