Refactor: Cleanup JJB for pre-commit
[ci-management.git] / jjb / akraino-templates / akraino-ta-common-macros.yaml
1 ---
2 # yamllint disable-file
3 ##############
4 # PARAMETERS #
5 ##############
6 - parameter:
7     name: ta-parameters
8     parameters:
9       - string:
10           name: SCM_REFSPEC_MANIFEST
11           default: refs/heads/master
12           description: ""
13           trim: "false"
14       - string:
15           name: SCM_REFSPEC_BUILD_TOOLS
16           default: refs/heads/master
17           description: ""
18           trim: "false"
19       - string:
20           name: SCM_REFSPEC_RPMBUILDER
21           default: refs/heads/master
22           description: ""
23           trim: "false"
24       - string:
25           name: SCM_PROJECT_TO_BUILD
26           default: ta/yarf
27           description: ""
28           trim: "false"
29       - string:
30           name: SCM_PROJECT_TO_BUILD_REFSPEC
31           default: refs/heads/master
32           description: ""
33           trim: "false"
34
35 #######
36 # SCM #
37 #######
38 - scm:
39     # Enhanced version of the global-jjb
40     name: ta-lf-infra-gerrit-scm
41     scm:
42       - git:
43           credentials-id: "{jenkins-ssh-credential}"
44           url: "{git-url}"
45           refspec: "{refspec}"
46           branches:
47             - "refs/heads/{branch}"
48           skip-tag: true
49           wipe-workspace: true
50           submodule:
51             recursive: "{submodule-recursive}"
52             timeout: "{submodule-timeout}"
53           choosing-strategy: "{choosing-strategy}"
54           basedir: "{basedir}"
55
56 - scm:
57     name: ta-lf-infra-gerrit-scm-merge
58     scm:
59       - ta-lf-infra-gerrit-scm:
60           jenkins-ssh-credential: "{jenkins-ssh-credential}"
61           git-url: "{git-url}"
62           refspec: "{refspec}"
63           branch: "{branch}"
64           submodule-recursive: "{submodule-recursive}"
65           submodule-timeout: "{submodule-timeout}"
66           basedir: "{basedir}"
67           choosing-strategy: default
68
69 - scm:
70     name: ta-lf-infra-gerrit-scm-verify
71     scm:
72       - ta-lf-infra-gerrit-scm:
73           jenkins-ssh-credential: "{jenkins-ssh-credential}"
74           git-url: "{git-url}"
75           refspec: "{refspec}"
76           branch: "{branch}"
77           submodule-recursive: "{submodule-recursive}"
78           submodule-timeout: "{submodule-timeout}"
79           basedir: "{basedir}"
80           choosing-strategy: gerrit
81
82 ###########
83 # BUILDER #
84 ###########
85 - builder:
86     name: lf-display-node-uuid
87     builders:
88       # yamllint disable rule:line-length
89       - shell: |2-
90             echo "---> Node UUID:"
91             curl -s http://169.254.169.254/openstack/latest/meta_data.json | python -c 'import sys, json; data = json.load(sys.stdin); print(data["uuid"])' || true
92       # yamllint enable rule:line-length
93
94 - builder:
95     name: ta-builder-tox
96     builders:
97       - shell: |2-
98           #!/bin/bash -ex
99           source ~/lf-env.sh
100
101           lf-activate-venv tox
102           tox --version
103           for f in $(find $GERRIT_PROJECT -name tox.ini); do
104               pushd $(dirname $f)
105               tox
106               popd
107           done
108
109 - builder:
110     name: ta-builder-rpm
111     builders:
112       - shell: |2-
113           #!/bin/bash -ex
114           #  Skip RPM build in case no *.spec file is found within the {project-to-build}
115           if [ -n "$(find {project-to-build} -name '*.spec')" ]; then
116               if apt --version >/dev/null 2>&1; then
117                   # We need a specific version of mock (1.4.14) and devtools
118                   # not available in Ubuntu/Debian repos, so fetch them from RHEL mirrors
119                   if [ "$(mock --version 2>/dev/null)" != '1.4.14' ]; then
120                       sudo groupadd mock || true
121                       sudo usermod -aG mock $USER
122                       sudo apt update
123                       # Explicitly install mock dependencies
124                       sudo apt install -y createrepo alien systemd-container python-pip \
125                                           python-peak.util.decorators yum-utils usermode pigz
126                       wget http://vault.centos.org/centos/7.6.1810/os/x86_64/Packages/rpmdevtools-8.3-5.el7.noarch.rpm \
127                            https://kojipkgs.fedoraproject.org/packages/mock/1.4.14/2.el7/noarch/mock-1.4.14-2.el7.noarch.rpm
128                       sudo alien -d *.rpm
129                       sudo dpkg --force-overwrite -i *.deb
130                       rm -rf *.rpm *.deb
131                       # RHEL tools hardcode the full path for certain distro tools
132                       sudo ln -sf /bin/tar /usr/bin/gtar
133                       sudo ln -sf /bin/machinectl /bin/df /usr/bin/
134                       # Some mock dependencies are only available via pip
135                       sudo pip install distro pyroute2 lxml urllib3
136                   fi
137               else
138                   sudo yum install -y createrepo
139               fi
140               ta/build-tools/build_rpms.sh \
141                -m ta/manifest \
142                -r ta/rpmbuilder \
143                -w work \
144                {project-to-build}
145               find work/
146           fi
147
148 - builder:
149     name: ta-builder-scm
150     builders:
151       - shell: |2-
152           #!/bin/bash -ex
153           rm -rf {project}
154           git clone {git-url}/{project} {project}
155           pushd {project}
156           if echo {ref} | grep -q "refs/"; then
157               git fetch origin {ref}
158               git checkout FETCH_HEAD
159           else
160               git checkout {ref}
161           fi
162           popd
163
164 - builder:
165     name: ta-lf-infra-ship-rpms
166     builders:
167       # Ensure no pre-existing .netrc files are overriding logs config
168       - lf-provide-maven-settings-cleanup
169       - config-file-provider:
170           files:
171             - file-id: "ta-settings"
172               variable: "SETTINGS_FILE"
173       - inject:
174           properties-content: "ALT_NEXUS_URL=https://nexus3.akraino.org"
175       - lf-infra-create-netrc:
176           server-id: rpm.snapshots
177       - inject:
178           properties-content: |
179             ALT_NEXUS_URL=
180             SERVER_ID=
181       - shell: !include-raw:
182           # Ensure python-tools are installed in case job template does not
183           # call the lf-infra-pre-build macro.
184           - ../../global-jjb/shell/python-tools-install.sh
185       - shell: !include-raw:
186           - ../shell/ta-rpm-deploy.sh
187       - shell: !include-raw:
188           - ../../global-jjb/shell/logs-clear-credentials.sh
189
190 - builder:
191     name: ta-lf-infra-ship-isos
192     builders:
193       # Ensure no pre-existing .netrc files are overriding logs config
194       - lf-provide-maven-settings-cleanup
195       - config-file-provider:
196           files:
197             - file-id: "ta-settings"
198               variable: "SETTINGS_FILE"
199       - lf-infra-create-netrc:
200           server-id: images-snapshots
201       - shell: !include-raw:
202           # Ensure python-tools are installed in case job template does not
203           # call the lf-infra-pre-build macro.
204           - ../../global-jjb/shell/python-tools-install.sh
205       - shell: !include-raw:
206           - ../shell/ta-iso-deploy.sh
207       - shell: !include-raw:
208           - ../../global-jjb/shell/logs-clear-credentials.sh
209
210 - builder:
211     name: ta-builder-job-verify
212     builders:
213       - ta-builder-scm:
214           git-url: "{git-url}"
215           project: "ta/manifest"
216           ref: "$SCM_REFSPEC_MANIFEST"
217       - ta-builder-scm:
218           git-url: "{git-url}"
219           project: "ta/build-tools"
220           ref: "$SCM_REFSPEC_BUILD_TOOLS"
221       - ta-builder-scm:
222           git-url: "{git-url}"
223           project: "ta/rpmbuilder"
224           ref: "$SCM_REFSPEC_RPMBUILDER"
225       - ta-builder-tox
226       - ta-builder-rpm:
227           project-to-build: "$GERRIT_PROJECT"
228
229 - builder:
230     name: ta-builder-job-verify-ta/rpmbuilder
231     builders:
232       - ta-builder-scm:
233           git-url: "{git-url}"
234           project: "ta/manifest"
235           ref: "$SCM_REFSPEC_MANIFEST"
236       - ta-builder-scm:
237           git-url: "{git-url}"
238           project: "ta/build-tools"
239           ref: "$SCM_REFSPEC_BUILD_TOOLS"
240       - ta-builder-scm:
241           git-url: "{git-url}"
242           project: "$SCM_PROJECT_TO_BUILD"
243           ref: "$SCM_PROJECT_TO_BUILD_REFSPEC"
244       - ta-builder-tox
245       - ta-builder-rpm:
246           # Just package some random project to verify "rpmbuilder" changes
247           project-to-build: "$SCM_PROJECT_TO_BUILD"
248
249 - builder:
250     name: ta-builder-job-merge
251     builders:
252       - ta-builder-scm:
253           git-url: "{git-url}"
254           project: "ta/manifest"
255           ref: "$SCM_REFSPEC_MANIFEST"
256       - ta-builder-scm:
257           git-url: "{git-url}"
258           project: "ta/build-tools"
259           ref: "$SCM_REFSPEC_BUILD_TOOLS"
260       - ta-builder-scm:
261           git-url: "{git-url}"
262           project: "ta/rpmbuilder"
263           ref: "$SCM_REFSPEC_RPMBUILDER"
264       - ta-builder-rpm:
265           project-to-build: "$GERRIT_PROJECT"
266       - ta-lf-infra-ship-rpms
267
268 - builder:
269     name: ta-builder-install-docker
270     builders:
271       - shell: |2-
272           #!/bin/bash -ex
273           if apt --version 2>1 >/dev/null; then
274               sudo chmod +r /boot/vmlinuz*
275               if ! docker --version 2>1 >/dev/null; then
276                   sudo apt update
277                   sudo apt install -y apt-transport-https ca-certificates curl software-properties-common rename
278                   curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
279                   sudo add-apt-repository -y "deb http://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
280                   sudo apt update
281                   sudo apt install -y docker-ce
282               fi
283           else
284               sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
285               sudo yum -y install docker-ce docker-ce-cli containerd.io
286           fi
287           sudo mkdir -p /etc/docker/
288           echo '{"experimental":true}' | sudo tee /etc/docker/daemon.json
289           sudo systemctl start docker
290           # Ugly hack to make docker usable for non-root
291           # (adding to the group would require re-login)
292           sudo chmod 777 /var/run/docker.sock
293
294 - builder:
295     name: ta-builder-install-build-tools
296     builders:
297       - shell: |2-
298           #!/bin/bash -ex
299           if apt --version 2>1 >/dev/null; then
300               if ! createrepo --version 2>1 >/dev/null; then
301                   sudo apt update
302                   sudo apt install -y createrepo libguestfs-tools jq libvirt-daemon-system
303               fi
304           else
305               sudo yum -y install createrepo libguestfs-tools-c jq
306           fi
307           sudo systemctl start libvirtd
308           systemctl status libvirtd
309
310 ###########
311 # TRIGGER #
312 ###########
313
314 - trigger:
315     name: ta-trigger-job-verify
316     triggers:
317       - gerrit:
318           server-name: "{gerrit-server-name}"
319           trigger-on:
320             - patchset-created-event:
321                 exclude-drafts: "false"
322                 exclude-trivial-rebase: "false"
323                 exclude-no-code-change: "false"
324             - draft-published-event
325             - comment-added-contains-event:
326                 comment-contains-value: "recheck"
327             - comment-added-contains-event:
328                 comment-contains-value: "reverify"
329           projects:
330             - project-compare-type: "ANT"
331               project-pattern: "{project}"
332               branches:
333                 - branch-compare-type: "ANT"
334                   branch-pattern: "**/{branch}"
335           readable-message: true
336           skip-vote:
337             successful: "{gerrit-skip-vote}"
338             failed: "{gerrit-skip-vote}"
339             unstable: "{gerrit-skip-vote}"
340             notbuilt: "{gerrit-skip-vote}"
341
342 - trigger:
343     name: ta-trigger-job-merge
344     triggers:
345       - gerrit:
346           server-name: "{gerrit-server-name}"
347           trigger-on:
348             # Not sure if it would be better to use "change-merged" here and just clone the master
349             # branch. With the current approach the SCM can be identical in verify and merge jobs.
350             - ref-updated-event
351             - comment-added-contains-event:
352                 comment-contains-value: "remerge"
353           projects:
354             - project-compare-type: "ANT"
355               project-pattern: "{project}"
356               branches:
357                 - branch-compare-type: "ANT"
358                   branch-pattern: "**/{branch}"
359           readable-message: true
360
361 #############
362 # PUBLISHER #
363 #############
364
365 - publisher:
366     name: ta-publisher-job-verify
367     publishers:
368       - lf-infra-publish
369
370 - publisher:
371     name: ta-publisher-job-merge
372     publishers:
373       - lf-infra-publish
374       - ta-publisher-ci-build:
375           arch: "{arch}"
376       - trigger-parameterized-builds:
377           - project: "ta-ci-build-{arch}"
378             condition: UNSTABLE_OR_BETTER
379             trigger-with-no-params: true
380
381 - publisher:
382     name: ta-publisher-ci-build
383     publishers:
384       - lf-infra-publish
385       - email:
386           recipients: !j2: |
387             {%- if 'arm64' in arch -%}
388             armband@enea.com
389             {%- endif -%}