92d315cb18d04fb3f879ea651dd29e595ce9c62f
[eliot.git] / base-macros.yaml
1 ---
2 # Base macros
3 #
4 # NOTE: make sure macros are listed in execution ordered.
5 #
6 # 1. parameters/properties
7 # 2. scm
8 # 3. triggers
9 # 4. wrappers
10 # 5. prebuilders (maven only, configured like Builders)
11 # 6. builders (maven, freestyle, matrix, etc..)
12 # 7. postbuilders (maven only, configured like Builders)
13 # 8. publishers/reporters/notifications
14
15 - parameter:
16     name: project-parameter
17     parameters:
18       - string:
19           name: PROJECT
20           default: '{project}'
21           description: "JJB configured PROJECT parameter"
22       - string:
23           name: GS_BASE
24           default: artifacts.akraino.org/$PROJECT
25           description: "URL to Google Storage."
26       - string:
27           name: BRANCH
28           default: '{branch}'
29           description: "JJB configured BRANCH parameter"
30       - string:
31           name: GERRIT_BRANCH
32           default: '{branch}'
33           description: "JJB configured GERRIT_BRANCH parameter (deprecated)"
34       - string:
35           name: GERRIT_REFSPEC
36           default: 'refs/heads/{branch}'
37           description: "Default refspec needed for manually triggering."
38
39
40 - property:
41     name: logrotate-default
42     properties:
43       - build-discarder:
44           days-to-keep: 60
45           num-to-keep: 200
46           artifact-days-to-keep: 60
47           artifact-num-to-keep: 200
48
49 - scm:
50     name: git-scm
51     scm:
52       - git: &git-scm-defaults
53           credentials-id: 'jenkins-ssh'
54           url: '$GIT_BASE'
55           branches:
56             - 'origin/$BRANCH'
57           timeout: 15
58           per-build-tag: false
59           skip-tag: true
60           shallow-clone: false
61           use-author: false
62           ignore-notify: false
63           wipe-workspace: true
64           prune: false
65
66 - scm:
67     name: git-scm-gerrit
68     scm:
69       - git:
70           choosing-strategy: 'gerrit'
71           refspec: '$GERRIT_REFSPEC'
72           <<: *git-scm-defaults
73
74 - scm:
75     name: git-scm-gerrit-with-submodules
76     scm:
77       - git:
78           choosing-strategy: 'gerrit'
79           refspec: '$GERRIT_REFSPEC'
80           submodule:
81             recursive: true
82             timeout: 20
83           <<: *git-scm-defaults
84
85 - trigger:
86     name: 'daily-trigger-disabled'
87     triggers:
88       - timed: ''
89
90 - trigger:
91     name: 'weekly-trigger-disabled'
92     triggers:
93       - timed: ''
94
95 - trigger:
96     name: gerrit-trigger-patchset-created
97     triggers:
98       - gerrit:
99           server-name: 'gerrit.akraino.org'
100           trigger-on:
101             - patchset-created-event:
102                 exclude-drafts: 'false'
103                 exclude-trivial-rebase: 'false'
104                 exclude-no-code-change: 'false'
105             - draft-published-event
106             - comment-added-contains-event:
107                 comment-contains-value: 'recheck'
108             - comment-added-contains-event:
109                 comment-contains-value: 'reverify'
110           projects:
111             - project-compare-type: 'ANT'
112               project-pattern: '{project}'
113               branches:
114                 - branch-compare-type: 'ANT'
115                   branch-pattern: '**/{branch}'
116               file-paths:
117                 - compare-type: 'ANT'
118                   pattern: '{files}'
119           skip-vote:
120             successful: false
121             failed: false
122             unstable: false
123             notbuilt: false
124
125 - wrapper:
126     name: ssh-agent-wrapper
127     wrappers:
128       - ssh-agent-credentials:
129           users:
130             - 'jenkins-ssh'
131
132 - wrapper:
133     name: build-timeout
134     wrappers:
135       - timeout:
136           timeout: '{timeout}'
137           timeout-var: 'BUILD_TIMEOUT'
138           fail: true
139
140 - wrapper:
141     name: fix-workspace-permissions
142     wrappers:
143       - pre-scm-buildstep:
144           - shell: |
145              #!/bin/bash
146              sudo chown -R $USER:$USER $WORKSPACE || exit 1
147
148 - builder:
149     name: upload-under-review-docs-to-akraino-artifacts
150     builders:
151       - shell: |
152           #!/bin/bash
153           set -o errexit
154           set -o pipefail
155           set -o xtrace
156           export PATH=$PATH:/usr/local/bin/
157
158           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
159           [[ -d docs/_build/ ]] || exit 0
160
161           echo
162           echo "###########################"
163           echo "UPLOADING DOCS UNDER REVIEW"
164           echo "###########################"
165           echo
166
167           gs_base="artifacts.akraino.org/$PROJECT/review"
168           gs_path="$gs_base/$GERRIT_CHANGE_NUMBER"
169           local_path="upload/$GERRIT_CHANGE_NUMBER"
170
171           mkdir -p upload
172           mv docs/_build/html/ "$local_path"
173           gsutil -m cp -r "$local_path" "gs://$gs_base"
174
175           gsutil -m setmeta \
176               -h "Content-Type:text/html" \
177               -h "Cache-Control:private, max-age=0, no-transform" \
178               "gs://$gs_path"/**.html > /dev/null 2>&1
179
180           echo "Document link(s):" >> gerrit_comment.txt
181           find "$local_path" | grep -e 'index.html$' -e 'pdf$' | \
182               sed -e "s|^$local_path|    http://$gs_path|" >> gerrit_comment.txt
183
184 # To take advantage of this macro, have your build write
185 # out the file 'gerrit_comment.txt' with information to post
186 # back to gerrit and include this macro in the list of builders.
187 - builder:
188     name: report-build-result-to-gerrit
189     builders:
190       - shell: |
191           #!/bin/bash
192           set -o errexit
193           set -o pipefail
194           set -o xtrace
195           export PATH=$PATH:/usr/local/bin/
196           if [[ -e gerrit_comment.txt ]] ; then
197               echo
198               echo "posting review comment to gerrit..."
199               echo
200               cat gerrit_comment.txt
201               echo
202               ssh -p 29418 gerrit.akraino.org \
203                   "gerrit review -p $GERRIT_PROJECT \
204                    -m '$(cat gerrit_comment.txt)' \
205                    $GERRIT_PATCHSET_REVISION \
206                    --notify NONE"
207           fi
208
209 - builder:
210     name: remove-old-docs-from-akraino-artifacts
211     builders:
212       - shell: |
213           #!/bin/bash
214           set -o errexit
215           set -o pipefail
216           set -o xtrace
217           export PATH=$PATH:/usr/local/bin/
218
219           [[ $GERRIT_CHANGE_NUMBER =~ .+ ]]
220
221           gs_path="artifacts.akraino.org/$PROJECT/review/$GERRIT_CHANGE_NUMBER"
222
223           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
224               echo
225               echo "Deleting Out-of-dated Documents..."
226               gsutil -m rm -r "gs://$gs_path"
227           fi
228           gs_path="artifacts.akraino.org/review/$GERRIT_CHANGE_NUMBER"
229
230           if gsutil ls "gs://$gs_path" > /dev/null 2>&1 ; then
231               echo
232               echo "Deleting Out-of-dated Documents..."
233               gsutil -m rm -r "gs://$gs_path"
234           fi
235
236 - builder:
237     name: upload-review-docs
238     builders:
239       - upload-under-review-docs-to-akraino-artifacts
240       - report-build-result-to-gerrit
241
242
243 - builder:
244     name: clean-workspace
245     builders:
246       - shell: |
247           #!/bin/bash
248           set -o errexit
249           set -o nounset
250           set -o pipefail
251           sudo /bin/rm -rf "$WORKSPACE"
252
253 - builder:
254     name: clean-workspace-log
255     builders:
256       - shell: |
257           find $WORKSPACE -type f -name '*.log' | xargs rm -f
258
259 - publisher:
260     name: archive-artifacts
261     publishers:
262       - archive:
263           artifacts: '{artifacts}'
264           allow-empty: true
265           fingerprint: true
266           latest-only: true
267
268 - publisher:
269     name: publish-coverage
270     publishers:
271       - cobertura:
272           report-file: "coverage.xml"
273           only-stable: "true"
274           health-auto-update: "false"
275           stability-auto-update: "false"
276           zoom-coverage-chart: "true"
277           targets:
278             - files:
279                 healthy: 10
280                 unhealthy: 20
281                 failing: 30
282             - method:
283                 healthy: 50
284                 unhealthy: 40
285                 failing: 30