Merge "Fix chown in jenkins slave connection script"
[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, nodes
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             if isinstance(doctree[0], nodes.title):
169                 title = doctree[0]
170             else:
171                 for c in doctree.children:
172                     if isinstance(c, nodes.section):
173                         title = c[0]
174                         break
175             print title.astext()"
176             _git_sha1="$(git rev-parse HEAD)"
177
178             git clone ssh://gerrit.opnfv.org:29418/releng
179             [[ -d releng ]]
180
181             find docs/ -name 'index.rst' -printf '%h\n' | while read dir
182             do
183                 _name="${dir##*/}"
184                 _build="$dir/build"
185                 _output="docs/output/$_name"
186
187                 echo
188                 echo "#################${dir//?/#}"
189                 echo "Building DOCS in $dir"
190                 echo "#################${dir//?/#}"
191                 echo
192
193                 sed -i "s/_sha1_/$_git_sha1/g" "$dir/index.rst"
194
195                 if [[ ! -f "$dir/conf.py" ]] ; then
196                     cp releng/docs/etc/conf.py "$dir/conf.py"
197                     _title=$(cd $dir; python -c "$_get_title_script")
198                     echo "latex_documents = [('index', '$_name.tex', '$_title', 'OPNFV', 'manual'),]" >> "$dir/conf.py"
199                 fi
200                 cp -f releng/docs/etc/opnfv-logo.png "$dir/opnfv-logo.png"
201
202                 mkdir -p "$_output"
203
204                 sphinx-build -b html -E "$dir" "$_output"
205
206                 # Note: PDF creation may fail in project doc builds.
207                 #       We allow this test to be marked as succeeded with
208                 #       failure in PDF creation, but leave message to fix it.
209                 #       Any failure has to be fixed before B release.
210                 {
211                     sphinx-build -b latex -E "$dir" "$_build"
212                     make -C "$_build" LATEXOPTS='--interaction=nonstopmode' all-pdf
213                     mv "$_build/$_name.pdf" "$_output"
214                 } || {
215                     _msg="Error: PDF creation for $dir has failed, please fix source rst file(s)."
216                     echo
217                     echo "$_msg"
218                     echo
219                     echo "$_msg" >> gerrit_comment.txt
220                 }
221             done
222
223 - builder:
224     name: upload-under-review-docs-to-opnfv-artifacts
225     builders:
226         - shell: |
227             #!/bin/bash -e
228             set -o pipefail
229             export PATH=$PATH:/usr/local/bin/
230
231             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
232             [[ -d docs/output ]]
233
234             echo
235             echo "###########################"
236             echo "UPLOADING DOCS UNDER REVIEW"
237             echo "###########################"
238             echo
239
240             gs_base="artifacts.opnfv.org/review"
241             gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
242             local_path="docs/$GERRIT_CHANGE_NUMBER"
243
244             mv docs/output "$local_path"
245             gsutil -m cp -r "$local_path" "gs://$gs_base"
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: upload-merged-docs-to-opnfv-artifacts
260     builders:
261         - shell: |
262             #!/bin/bash -e
263             set -o pipefail
264             export PATH=$PATH:/usr/local/bin/
265
266             [[ -d docs/output ]]
267
268             echo
269             echo "#####################"
270             echo "UPLOADING MERGED DOCS"
271             echo "#####################"
272             echo
273
274             if [[ "$GERRIT_BRANCH" == "master" ]] ; then
275                 gs_base="artifacts.opnfv.org/$GERRIT_PROJECT"
276             else
277                 gs_base="artifacts.opnfv.org/$GERRIT_PROJECT/$GERRIT_BRANCH"
278             fi
279             gs_path="$gs_base/docs"
280             local_path="docs/docs"
281
282             mv docs/output "$local_path"
283             gsutil -m cp -r "$local_path" "gs://$gs_base"
284
285             if gsutil ls "gs://$gs_path" | grep -e 'html$' > /dev/null 2>&1 ; then
286                 gsutil -m setmeta \
287                     -h "Content-Type:text/html" \
288                     -h "Cache-Control:private, max-age=0, no-transform" \
289                     "gs://$gs_path"/**.html
290             fi
291
292             echo "Document link(s):" >> gerrit_comment.txt
293             find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
294                 sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
295
296 - builder:
297     name: report-docs-build-result-to-gerrit
298     builders:
299         - shell: |
300             #!/bin/bash -e
301             export PATH=$PATH:/usr/local/bin/
302             if [[ -e gerrit_comment.txt ]] ; then
303                 echo
304                 echo "posting review comment to gerrit..."
305                 echo
306                 cat gerrit_comment.txt
307                 echo
308                 ssh -p 29418 gerrit.opnfv.org \
309                     "gerrit review -p $GERRIT_PROJECT \
310                      -m '$(cat gerrit_comment.txt)' \
311                      $GERRIT_PATCHSET_REVISION"
312             fi
313
314 - builder:
315     name: remove-old-docs-from-opnfv-artifacts
316     builders:
317         - shell: |
318             #!/bin/bash -e
319             export PATH=$PATH:/usr/local/bin/
320
321             [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
322
323             gs_path="artifacts.opnfv.org/review/$GERRIT_CHANGE_NUMBER"
324
325             if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
326                 echo
327                 echo "Deleting Out-of-dated Documents..."
328                 gsutil -m rm -r "gs://$gs_path"
329             fi
330
331 - builder:
332     name: upload-review-docs
333     builders:
334         - build-html-and-pdf-docs-output
335         - upload-under-review-docs-to-opnfv-artifacts
336         - report-docs-build-result-to-gerrit
337
338 - builder:
339     name: upload-merged-docs
340     builders:
341         - build-html-and-pdf-docs-output
342         - upload-merged-docs-to-opnfv-artifacts
343         - report-docs-build-result-to-gerrit
344         - remove-old-docs-from-opnfv-artifacts