5ef8a170eef268ba037af3775708ebe5e97d0aa4
[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
11 - parameter:
12     name: gerrit-parameter
13     parameters:
14         - string:
15             name: GERRIT_BRANCH
16             default: '{branch}'
17             description: "JJB configured GERRIT_BRANCH parameter"
18
19 - scm:
20     name: git-scm
21     scm:
22         - git:
23             credentials-id: '{credentials-id}'
24             url: '$GIT_BASE'
25             refspec: ''
26             branches:
27                 - 'origin/{branch}'
28             skip-tag: true
29             wipe-workspace: true
30
31 - scm:
32     name: gerrit-trigger-scm
33     scm:
34         - git:
35             credentials-id: '{credentials-id}'
36             url: '$GIT_BASE'
37             refspec: '{refspec}'
38             branches:
39                 - 'origin/$GERRIT_BRANCH'
40             skip-tag: true
41             choosing-strategy: '{choosing-strategy}'
42
43 - wrapper:
44     name: build-timeout
45     wrappers:
46         - timeout:
47             type: absolute
48             timeout: 360
49             fail: true
50
51 - trigger:
52     name: gerrit-trigger-patch-submitted
53     triggers:
54         - gerrit:
55             server-name: 'gerrit.opnfv.org'
56             trigger-on:
57                 - patchset-created-event:
58                     exclude-drafts: 'false'
59                     exclude-trivial-rebase: 'false'
60                     exclude-no-code-change: 'false'
61                 - draft-published-event
62                 - comment-added-contains-event:
63                     comment-contains-value: 'recheck'
64             projects:
65               - project-compare-type: 'ANT'
66                 project-pattern: '{name}'
67                 branches:
68                   - branch-compare-type: 'ANT'
69                     branch-pattern: '**/{branch}'
70
71 - trigger:
72     name: gerrit-trigger-patch-merged
73     triggers:
74         - gerrit:
75             server-name: 'gerrit.opnfv.org'
76             trigger-on:
77                 - change-merged-event
78                 - comment-added-contains-event:
79                     comment-contains-value: 'remerge'
80             projects:
81               - project-compare-type: 'ANT'
82                 project-pattern: '{name}'
83                 branches:
84                   - branch-compare-type: 'ANT'
85                     branch-pattern: '**/{branch}'
86
87 - publisher:
88     name: archive-artifacts
89     publishers:
90         - archive:
91             artifacts: '{artifacts}'
92             allow-empty: true
93             fingerprint: true
94             latest-only: true
95
96 - publisher:
97     name: email-notification
98     publishers:
99         - email-ext:
100             recipients: 'jenkins@lists.opnfv.org'
101             reply-to:
102             content-type: default
103             subject: '{email-prefix} $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!'
104             body: |
105                 $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
106
107                 Check console output at $BUILD_URL to view the results.
108             unstable: true
109             fixed: true
110             send-to:
111                 - developers
112                 - recipients
113
114 - publisher:
115         name: jacoco-report
116         publishers:
117             - jacoco:
118                 exec-pattern: "**/**.exec"
119                 class-pattern: "**/classes"
120                 source-pattern: "**/src/main/java"
121                 exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**"
122                 status-update: true
123                 targets:
124                   - branch:
125                       healthy: 10
126                       unhealthy: 20
127                   - method:
128                       healthy: 50
129                       unhealthy: 40
130
131
132 - builder:
133     name: test-macro
134     builders:
135         - shell: 'echo testing macro "test-macro"'
136
137 - builder:
138     name: wipe-org-opendaylight-repo
139     builders:
140         - shell: 'if [ -d /tmp/r/org/opendaylight ]; then rm -rf /tmp/r/org/opendaylight; fi'
141
142 - builder:
143     name: jacoco-nojava-workaround
144     builders:
145         - shell: 'mkdir -p $WORKSPACE/target/classes'
146
147
148 # New Releng macros
149
150 - builder:
151     name: build-html-and-pdf-docs-output
152     builders:
153         - shell: |
154             #!/bin/bash -e
155             set -o pipefail
156             export PATH=$PATH:/usr/local/bin/
157
158             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
159
160             _get_title_script="
161             import os
162             from docutils import core
163             with open('index.rst', 'r') as file:
164                 data = file.read()
165                 doctree = core.publish_doctree(data,
166                     settings_overrides={'report_level': 5,
167                                         'halt_level': 5})
168                 print doctree[0].astext()"
169             _git_sha1="$(git rev-parse HEAD)"
170
171             find docs/ -name 'index.rst' -printf '%h\n' | while read dir
172             do
173                 _name="${dir##*/}"
174                 _build="$dir/build"
175                 _output="docs/output/$_name"
176
177                 echo
178                 echo "#################${dir//?/#}"
179                 echo "Building DOCS in $dir"
180                 echo "#################${dir//?/#}"
181                 echo
182
183                 sed -i "s/_sha1_/$_git_sha1/g" "$dir/index.rst"
184
185                 if [[ ! -f "$dir/conf.py" ]] ; then
186                     cp "docs/etc/conf.py" "$dir/conf.py"
187                     _title=$(cd $dir; python -c "$_get_title_script")
188                     echo "latex_documents = [('index', '$_name.tex', '$_title', 'OPNFV', 'manual'),]" >> "$dir/conf.py"
189                 fi
190                 cp -f "docs/etc/opnfv-logo.png" "$dir/opnfv-logo.png"
191
192                 mkdir -p "$_output"
193
194                 sphinx-build -b html -E "$dir" "$_output"
195
196                 # Note: PDF creation may fail in project doc builds.
197                 #       We allow this test to be marked as succeeded with
198                 #       failure in PDF creation, but leave message to fix it.
199                 #       Any failure has to be fixed before B release.
200                 {
201                     sphinx-build -b latex -E "$dir" "$_build"
202                     make -C "$_build" LATEXOPTS='--interaction=nonstopmode' all-pdf
203                     mv "$_build"/*.pdf "$_output"
204                 } || {
205                     _msg="Error: PDF creation for $dir has failed, please fix source rst file(s)."
206                     echo
207                     echo "$_msg"
208                     echo
209                     echo "$_msg" >> gerrit_comment.txt
210                 }
211             done
212
213 - builder:
214     name: upload-under-review-docs-to-opnfv-artifacts
215     builders:
216         - shell: |
217             #!/bin/bash -e
218             set -o pipefail
219             export PATH=$PATH:/usr/local/bin/
220
221             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
222             [[ -d docs/output ]]
223
224             echo
225             echo "###########################"
226             echo "UPLOADING DOCS UNDER REVIEW"
227             echo "###########################"
228             echo
229
230             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
231
232             gsutil -m cp -r docs/output/* "gs://$gs_path"
233
234             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
235                 gsutil -m setmeta \
236                     -h "Content-Type:text/html" \
237                     -h "Cache-Control:private, max-age=0, no-transform" \
238                     "gs://$gs_path"/**.html
239             fi
240
241             echo "Document link(s):" >> gerrit_comment.txt
242             find docs/output | grep -e 'index.html$' -e 'pdf$' | \
243                 sed -e "s|^docs/output|    http://$gs_path|" >> gerrit_comment.txt
244
245 - builder:
246     name: upload-merged-docs-to-opnfv-artifacts
247     builders:
248         - shell: |
249             #!/bin/bash -e
250             set -o pipefail
251             export PATH=$PATH:/usr/local/bin/
252
253             [[ -d docs/output ]]
254
255             echo
256             echo "#####################"
257             echo "UPLOADING MERGED DOCS"
258             echo "#####################"
259             echo
260
261             if [[ "$GERRIT_BRANCH" == "master" ]] ; then
262                 gs_path="artifacts.opnfv.org/$GERRIT_PROJECT/docs"
263             else
264                 gs_path="artifacts.opnfv.org/$GERRIT_PROJECT/$GERRIT_BRANCH/docs"
265             fi
266
267             gsutil -m cp -r docs/output/* "gs://$gs_path"
268
269             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
270                 gsutil -m setmeta \
271                     -h "Content-Type:text/html" \
272                     -h "Cache-Control:private, max-age=0, no-transform" \
273                     "gs://$gs_path"/**.html
274             fi
275
276             echo "Document link(s):" >> gerrit_comment.txt
277             find docs/output | grep -e 'index.html$' -e 'pdf$' | \
278                 sed -e "s|^docs/output|    http://$gs_path|" >> gerrit_comment.txt
279
280 - builder:
281     name: report-docs-build-result-to-gerrit
282     builders:
283         - shell: |
284             #!/bin/bash -e
285             export PATH=$PATH:/usr/local/bin/
286             if [[ -e gerrit_comment.txt ]] ; then
287                 echo
288                 echo "posting review comment to gerrit..."
289                 echo
290                 cat gerrit_comment.txt
291                 echo
292                 ssh -p 29418 gerrit.opnfv.org \
293                     "gerrit review -p $GERRIT_PROJECT \
294                      -m '$(cat gerrit_comment.txt)' \
295                      $GERRIT_PATCHSET_REVISION"
296             fi
297
298 - builder:
299     name: remove-old-docs-from-opnfv-artifacts
300     builders:
301         - shell: |
302             #!/bin/bash -e
303             export PATH=$PATH:/usr/local/bin/
304
305             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
306
307             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
308
309             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
310                 echo
311                 echo "Deleting Out-of-dated Documents..."
312                 gsutil -m rm -r "gs://$gs_path"
313             fi
314
315 - builder:
316     name: upload-review-docs
317     builders:
318         - build-html-and-pdf-docs-output
319         - upload-under-review-docs-to-opnfv-artifacts
320         - report-docs-build-result-to-gerrit
321
322 - builder:
323     name: upload-merged-docs
324     builders:
325         - build-html-and-pdf-docs-output
326         - upload-merged-docs-to-opnfv-artifacts
327         - report-docs-build-result-to-gerrit
328         - remove-old-docs-from-opnfv-artifacts