2c03380cb92de853a00fc5a46b7a94a0f12790bb
[releng/builder.git] / jjb / releng-macros.yaml
1 # OLD Releng macros
2 ---
3 - property:
4     name: opendaylight-infra-properties
5     properties:
6       - build-discarder:
7           days-to-keep: '{build-days-to-keep}'
8           num-to-keep: 40
9           # Need to keep artifacts for at least 1 day as some projects need to
10           # be able to validate their artifacts and only allowing limited
11           # number of artifacts could make fast moving jobs lost their
12           # artifacts before the developers can test it.
13           artifact-days-to-keep: 1
14
15 - parameter:
16     name: opendaylight-infra-parameters
17     parameters:
18       - string:
19           name: PROJECT
20           default: '{project}'
21           description: 'Parameter to identify an ODL Gerrit project'
22       - string:
23           name: ARCHIVE_ARTIFACTS
24           default: >
25               {artifacts}
26               **/target/surefire-reports/*.txt
27               **/target/surefire-reports/*.xml
28               **/target/failsafe-reports/*.txt
29               **/target/failsafe-reports/*.xml
30               **/hs_err_*.log
31               **/target/feature/feature.xml
32               **/*.hprof
33           description: 'Space separated glob patterns for artifacts to archive into logs.opendaylight.org'
34       - string:
35           name: GERRIT_PROJECT
36           default: '{project}'
37           description: "GERRIT_PROJECT parameter if not given by trigger"
38       - string:
39           name: GERRIT_BRANCH
40           default: '{branch}'
41           description: "JJB configured GERRIT_BRANCH parameter"
42       - string:
43           name: GERRIT_REFSPEC
44           default: '{refspec}'
45           description: "GERRIT_REFSPEC parameter if not given by trigger"
46       - string:
47           name: STACK_NAME
48           default: '$SILO-$JOB_NAME-$BUILD_NUMBER'
49           description: "Used by Heat to generate a unique stack & vm name"
50       - string:
51           name: OS_CLOUD
52           default: '{os-cloud}'
53           description: |
54               The name of a cloud configuration in clouds.yaml. OS_CLOUD is a
55               variable name that is significant to openstack client as a
56               environment variable. Please refer to the documentation for
57               further details.
58               https://docs.openstack.org/developer/python-openstackclient/
59
60 - parameter:
61     name: build-tag
62     parameters:
63       - string:
64           name: BUILD_TAG
65           default: ''
66           description: 'Tag in Git to checkout'
67
68 - parameter:
69     name: controller-version-parameter
70     parameters:
71       - string:
72           name: ODL_VERSION
73           default: '{odl_version}'
74           description: 'Controller version (for use with openstacks networking_odl project)'
75
76 - parameter:
77     name: patches-to-build-parameter
78     parameters:
79       - string:
80           name: PATCHES_TO_BUILD
81           default: ''
82           description: |
83             Patches to add to distro in CSV project:changeset format (genius:32/53632/9,netvirt:59/50259/47)
84
85 - parameter:
86     name: run-test-parameter
87     parameters:
88       - string:
89           name: RUNTEST
90           default: '{run-test}'
91           description: 'Set true to run test after build'
92
93 - parameter:
94     name: distribution-branch-to-build-parameter
95     parameters:
96       - string:
97           name: DISTRIBUTION_BRANCH_TO_BUILD
98           default: 'master'
99           description: 'distribution repo branch to build with'
100
101 - parameter:
102     name: p2zip-parameter
103     parameters:
104       - string:
105           name: P2ZIP_URL
106           default: ''
107           description: 'Nexus staging profile id'
108
109 - parameter:
110     name: stage-id-parameter
111     parameters:
112       - string:
113           name: STAGING_PROFILE_ID
114           default: '{stage-id}'
115           description: 'Nexus staging profile id'
116
117 - parameter:
118     name: maven-exec
119     parameters:
120       - string:
121           name: MVN
122           default: '/w/tools/hudson.tasks.Maven_MavenInstallation/{maven-version}/bin/mvn'
123           description: 'Maven selector to be used by shell scripts'
124
125 - scm:
126     name: git-scm
127     scm:
128       - git:
129           credentials-id: 'opendaylight-jenkins-ssh'
130           url: '$GIT_BASE'
131           refspec: ''
132           branches:
133             - 'origin/{branch}'
134           skip-tag: true
135           wipe-workspace: true
136
137 - scm:
138     name: git-scm-with-submodules
139     scm:
140       - git:
141           credentials-id: 'opendaylight-jenkins-ssh'
142           url: '$GIT_BASE'
143           refspec: ''
144           branches:
145             - 'refs/heads/{branch}'
146           skip-tag: true
147           wipe-workspace: true
148           submodule:
149             recursive: true
150
151 - scm:
152     name: gerrit-trigger-scm
153     scm:
154       - git:
155           credentials-id: 'opendaylight-jenkins-ssh'
156           url: '$GIT_BASE'
157           refspec: '{refspec}'
158           branches:
159             - 'origin/$GERRIT_BRANCH'
160           skip-tag: true
161           choosing-strategy: '{choosing-strategy}'
162
163 - wrapper:
164     name: build-timeout
165     wrappers:
166       - timeout:
167           type: absolute
168           timeout: 360
169           fail: true
170
171 # This is a single macro to use for all jobs who vote on every (relevant) patch set.
172 # Only 'recheck' trigger word is supported, it always triggers the full set of relevant jobs,
173 # in order to prevent Jenkins from starting only a subset and still voting Verified+1.
174 # Arguments:
175 #     server: name of gerrit server to listen to
176 #     project: pattern to match triggering projects
177 #     branch: triggering branch name
178 #     files: pattern to match triggering filepaths
179 - trigger:
180     name: gerrit-trigger-patch-submitted
181     triggers:
182       - gerrit:
183           server-name: '{server}'
184           trigger-on:
185             - patchset-created-event:
186                 exclude-drafts: true
187                 exclude-trivial-rebase: false
188                 exclude-no-code-change: false
189             - draft-published-event
190             - comment-added-contains-event:
191                 comment-contains-value: recheck
192           projects:
193             - project-compare-type: ANT
194               project-pattern: '{project}'
195               branches:
196                 - branch-compare-type: ANT
197                   branch-pattern: '**/{branch}'
198               file-paths:
199                 - compare-type: ANT
200                   pattern: '{files}'
201
202 # TODO: Unify argument names across gerrit-trigger-* macros.
203 - trigger:
204     name: gerrit-trigger-patch-merged
205     triggers:
206       - gerrit:
207           server-name: '{server-name}'
208           trigger-on:
209             - change-merged-event
210             - comment-added-contains-event:
211                 comment-contains-value: 'remerge'
212           projects:
213             - project-compare-type: 'ANT'
214               project-pattern: '{name}'
215               branches:
216                 - branch-compare-type: 'ANT'
217                   branch-pattern: '**/{branch}'
218           skip-vote:
219             successful: true
220             failed: true
221             unstable: true
222             notbuilt: true
223           # Force Jenkins always vote the values it should already have voted
224           # during the prior verify phase
225           override-votes: true
226           gerrit-build-started-verified-value: 1
227           gerrit-build-successful-verified-value: 1
228           gerrit-build-failed-verified-value: 1
229           gerrit-build-unstable-verified-value: 1
230           gerrit-build-notbuilt-verified-value: 1
231           gerrit-build-started-codereview-value: 0
232           gerrit-build-successful-codereview-value: 0
233           gerrit-build-failed-codereview-value: 0
234           gerrit-build-unstable-codereview-value: 0
235           gerrit-build-notbuilt-codereview-value: 0
236
237 # TODO: Unify argument names across gerrit-trigger-* macros.
238 - trigger:
239     name: gerrit-trigger-patch-sonar
240     triggers:
241       - gerrit:
242           server-name: '{server-name}'
243           trigger-on:
244             - comment-added-contains-event:
245                 comment-contains-value: 'run-sonar'
246           projects:
247             - project-compare-type: 'ANT'
248               project-pattern: '{name}'
249               branches:
250                 - branch-compare-type: 'ANT'
251                   branch-pattern: '**/master'
252           skip-vote:
253             successful: true
254             failed: true
255             unstable: true
256             notbuilt: true
257
258 - publisher:
259     name: archive-artifacts
260     publishers:
261       - archive:
262           artifacts: '{artifacts}'
263           allow-empty: true
264           fingerprint: true
265           latest-only: true
266
267 - publisher:
268     name: email-notification
269     publishers:
270       - email-ext:
271           recipients: '{email-recipients}'
272           reply-to: ''
273           content-type: default
274           subject: '{email-prefix} $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!'
275           body: |
276               $PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS:
277
278               Please refer to the logs server URL for console logs when possible
279               and use the Jenkins Build URL as a last resort.
280
281               Console Logs URL:
282               https://logs.opendaylight.org/$SILO/$JENKINS_HOSTNAME/$JOB_NAME/$BUILD_NUMBER
283
284               Jenkins Build URL:
285               $BUILD_URL
286           unstable: true
287           fixed: true
288           send-to:
289             - recipients
290
291 - publisher:
292     name: jacoco-report
293     publishers:
294       - jacoco:
295           exec-pattern: "**/**.exec"
296           class-pattern: "**/classes"
297           source-pattern: "**/src/main/java"
298           exclusion-pattern: "**/gen/**,**/generated-sources/**,**/yang-gen**,**/pax/**"
299           status-update: true
300           targets:
301             - branch:
302                 healthy: 10
303                 unhealthy: 20
304             - method:
305                 healthy: 50
306                 unhealthy: 40
307
308 - builder:
309     name: opendaylight-infra-stack
310     # opendaylight-infra-stack.sh has a required variable {stack-template} that
311     # must be passed into this macro.
312     builders:
313       - shell: !include-raw: opendaylight-infra-stack.sh
314       - shell: !include-raw-escape: opendaylight-infra-copy-ssh-keys.sh
315
316 - builder:
317     name: opendaylight-infra-push-gerrit-patch
318     # opendaylight-infra-push-gerrit-patch.sh allows a job to push a patch to
319     # Gerrit in an automated fashion. This is meant for tasks that creates
320     # the same patch regularly and needs the ability to detect if an unreviewed
321     # patch already exists. In which case it will update the existing patch.
322     #
323     # Note: This patch assumes the $WORKSPACE contains the project repo with
324     #       the files changed already "git add" and waiting for a "git commit" call.
325     #
326     # This script requires the following JJB variables to be passed in:
327     #     {project}       Gerrit project-name
328     #     {gerrit-topic}  Gerrit topic, please make a unique topic.
329     #     {gerrit-commit-message} Commit message to assign to commit.
330     # NOTE: Requires git review to be installed on node.
331     builders:
332       - shell: !include-raw: opendaylight-infra-push-gerrit-patch.sh
333
334 - builder:
335     name: distribute-build-url
336     # Place URL of the current run of a build job to a file at given path.
337     builders:
338       - shell: |
339           #!/bin/bash
340           set +e  # DO NOT fail script if command returns non-zero.
341
342           echo "$BUILD_URL" > {path}/build.url
343
344           # DO NOT fail the build if the echo failed.
345           exit 0
346
347 - builder:
348     name: wipe-org-opendaylight-repo
349     builders:
350       - shell: 'if [ -d /tmp/r/org/opendaylight ]; then rm -rf /tmp/r/org/opendaylight; fi'
351
352 - builder:
353     name: wipe-local-maven-repo
354     builders:
355       - shell: 'if [ -d /tmp/r ]; then rm -rf /tmp/r; fi'
356
357 - builder:
358     name: jacoco-nojava-workaround
359     builders:
360       - shell: 'mkdir -p $WORKSPACE/target/classes $WORKSPACE/jacoco/classes'
361
362 - builder:
363     name: check-clm
364     builders:
365       - sonatype-clm:
366           application-name: '{application-name}'
367
368 - builder:
369     name: releng-check-unicode
370     builders:
371       - shell: |
372           $WORKSPACE/scripts/check-unicode.sh jjb/
373
374 - builder:
375     name: provide-maven-settings
376     builders:
377       - config-file-provider:
378           files:
379             - file-id: '{global-settings-file}'
380               variable: 'GLOBAL_SETTINGS_FILE'
381             - file-id: '{settings-file}'
382               variable: 'SETTINGS_FILE'
383
384 - builder:
385     name: releng-fetch-p2zip-if-necessary
386     builders:
387       - shell: |
388           # Cleanup any existing zips and metadata before we download the new update site
389           rm -f *.zip *.xml
390       - conditional-step:
391           condition-kind: strings-match
392           condition-string1: '$P2ZIP_URL'
393           condition-string2: ''
394           condition-basedir: workspace
395           steps:
396             # TODO: Figure out latest snapshot version number to pull rather than hardcoding 1.1.1-SNAPSHOT
397             - maven-target:
398                 maven-version: '{maven-version}'
399                 goals: >
400                     org.apache.maven.plugins:maven-dependency-plugin:get
401                     org.apache.maven.plugins:maven-dependency-plugin:copy
402                     -V -B
403                     -Dartifact=org.opendaylight.yangide:org.opendaylight.yangide.update-site:1.1.1-SNAPSHOT:zip
404                     -DoutputDirectory=$WORKSPACE
405                 settings: '{settings}'
406                 global-settings: '{global-settings}'
407
408 - builder:
409     name: releng-generate-p2pom
410     builders:
411       - shell: !include-raw: include-raw-generate-p2pom.sh
412
413 - builder:
414     name: releng-update-p2composite-metadata
415     builders:
416       - shell: !include-raw: include-raw-update-p2composite-metadata.sh
417       - conditional-step:
418           condition-kind: file-exists
419           condition-filename: deploy-composite-repo.xml
420           condition-basedir: workspace
421           steps:
422             - maven-target:
423                 maven-version: '{maven-version}'
424                 pom: 'deploy-composite-repo.xml'
425                 goals: 'clean deploy -V -B -Dmaven.repo.local=/tmp/r'
426                 settings: '{settings}'
427                 global-settings: '{global-settings}'
428
429 - builder:
430     name: releng-stage-release
431     builders:
432       - shell: !include-raw: include-raw-stage-release.sh
433
434 - wrapper:
435     # This wrapper is required for all jobs as it configures the wrappers
436     # needed by OpenDaylight infra.
437     name: opendaylight-infra-wrappers
438     wrappers:
439       - mask-passwords
440       - config-file-provider:
441           files:
442             - file-id: npmrc
443               target: '$HOME/.npmrc'
444             - file-id: rackspace-heat
445               target: '$HOME/.config/openstack/clouds.yaml'
446       - timeout:
447           type: absolute
448           timeout: '{build-timeout}'
449           timeout-var: 'BUILD_TIMEOUT'
450           fail: true
451       - timestamps
452       - ssh-agent-credentials:
453           users:
454             - 'opendaylight-jenkins-ssh'
455       - openstack:
456           single-use: true
457
458 - builder:
459     name: packer-validate
460     builders:
461       - config-file-provider:
462           files:
463             - file-id: 'packer-cloud-env'
464               variable: 'CLOUDENV'
465       - shell: |
466           #!/bin/bash
467           cd packer
468           varfiles="../packer/vars/*"
469           templates="../packer/templates/*"
470           provision="../packer/provision/*.sh"
471           for v in $varfiles; do
472               [[ "${v##*/}" =~ ^(cloud-env.*)$ ]] && continue
473               for t in $templates; do
474                   export PACKER_LOG="yes" && \
475                   export PACKER_LOG_PATH="packer-validate-${v##*/}-${t##*/}.log" && \
476                               packer.io validate -var-file=$CLOUDENV \
477                               -var-file=$v $t
478                   if [ $? -ne 0 ]; then
479                       break
480                   fi
481               done
482           done
483
484 - builder:
485     name: packer-build
486     builders:
487       - config-file-provider:
488           files:
489             - file-id: 'packer-cloud-env'
490               variable: 'CLOUDENV'
491       - shell: |
492           #!/bin/bash
493           cd packer
494           export PACKER_LOG="yes" && \
495           export PACKER_LOG_PATH="packer-build.log" && \
496                       packer.io build -color=false -var-file=$CLOUDENV \
497                        -var-file=../packer/vars/{platform}.json \
498                        ../packer/templates/{template}.json
499           # Split public and private cloud logs
500           grep -e 'public_cloud' packer-build.log > packer-build_public_cloud.log  2>&1
501           grep -e 'private_cloud' packer-build.log > packer-build_private_cloud.log 2>&1
502
503 - builder:
504     # TODO: Verify signature after downloading users public key from a locally created
505     # repository instead of the public keymesh. This requires a process in place to get ODL
506     # developers public keys into a local repository without increasing the job thoughput.
507     name: verify-gpg-signature
508     builders:
509       - shell: !include-raw: include-raw-verify-gpg-signatures.sh
510
511 - builder:
512     name: opendaylight-infra-jjbini
513     builders:
514       - config-file-provider:
515           files:
516             - file-id: 'jjbini'
517               target: '$HOME/.config/jenkins_jobs/jenkins_jobs.ini'
518
519 - builder:
520     name: distribution-check-wipe
521     # Step zero: Wipe file repositories up front.
522     builders:
523       - shell: |
524           echo "wipe r: the local Maven repository"
525           rm -rfv /tmp/r
526           echo "wipe n: the fake remote (Nexus) repository"
527           rm -rfv /tmp/n
528           echo "wipe t: the transient repository used in some manipulations"
529           rm -rfv /tmp/t
530
531 - builder:
532     name: distribution-check-build-project
533     # Step one: Online build of the project, using local repository /tmp/r/ and deploying artifacts to /tmp/n/.
534     # Ordinary SingleFeatureTest failures are detected in the verify job, so we can use "q" profile here.
535     # Arguments:
536     #   pom: Relative path to pom file to use. Typically '$GERRIT_PROJECT/pom.xml'.
537     builders:
538       - maven-target:
539           maven-version: 'mvn33'
540           pom: '{pom}'
541           goals: |
542               clean deploy dependency:tree
543               -DoutputFile=dependency_tree.txt
544               -Pq
545               -DaltDeploymentRepository=fake-nexus::default::file:///tmp/n/
546               {mvn-opts}
547           java-opts:
548             - '-Xmx4096m -XX:MaxPermSize=1024m -Dmaven.compile.fork=true'
549           settings: 'integration-settings'
550           settings-type: cfp
551           global-settings: 'global-settings'
552           global-settings-type: cfp
553
554 - builder:
555     name: distribution-check-verify-groupid
556     # Step two: Verify all deployed artifacts belong to the project's groupId.
557     # This is done by moving the allowed directories out of /tmp/n and checking no files remained there.
558     # The correct directory is derived from $GERRIT_PROJECT.
559     # TODO: Verify all deployed artifacts are snapshots.
560     # Arguments:
561     #   gerrit-project: Project name as nexus URI part. Typically '$GERRIT_PROJECT'.
562     builders:
563       - shell: |
564           mkdir -p /tmp/t/org/opendaylight/{gerrit-project}
565           mv /tmp/n/org/opendaylight/{gerrit-project}/* /tmp/t/org/opendaylight/{gerrit-project}/
566           test -z "`find /tmp/n/ -type f`" || ( echo "ERROR: Mismatched groupId detected (see above)." && false )
567           rm -rf /tmp/n
568           mv /tmp/t /tmp/n
569
570 - builder:
571     name: distribution-check-download-deps
572     # Step three: Online build of integration distribution.
573     # This step is mainly used for downloading other project artifacts.
574     # Running SingleFeaturesTest here does not seem to be required, so -Pq is used again.
575     # Arguments:
576     #   dist-pom: Relative path to pom file to use. 'distribution/pom.xml' is recommended.
577     builders:
578       - maven-target:
579           maven-version: 'mvn33'
580           pom: '{dist-pom}'
581           goals: |
582               clean install dependency:tree
583               -DoutputFile=dependency_tree.txt
584               -Pq
585               {mvn-opts}
586           java-opts:
587             - '-Xmx1024m -XX:MaxPermSize=256m -Dmaven.compile.fork=true'
588           settings: 'integration-settings'
589           settings-type: cfp
590           global-settings: 'global-settings'
591           global-settings-type: cfp
592
593 - builder:
594     name: distribution-check-delete-snapshots
595     # Step four: Delete snapshot artifacts from the local repository.
596     # This is critical to detect orphaned artifacts or missing project-internal dependency declarations.
597     # Also other files related to maven repository resolution are removed,
598     # and then empty directories are removed, in order to simplify debugging.
599     builders:
600       - shell: !include-raw-escape: integration-distribution-delete-snaphot-artifacts.sh
601
602 - builder:
603     name: distribution-check-configure-remotes
604     # Now the ugly part. It seems that the only way to tell Maven 2+
605     # which remote repositories to use is via settings.xml file.
606     # So we create such a file here, but it needs most of odlparent:settings.xml
607     builders:
608       - shell: |
609           echo '
610           <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
611             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
612             xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
613             https://maven.apache.org/xsd/settings-1.0.0.xsd">
614             <profiles>
615               <profile>
616                 <id>opendaylight-release</id>
617                 <repositories>
618                   <repository>
619                     <id>opendaylight-mirror</id>
620                     <name>opendaylight</name>
621                     <url>https://nexus.opendaylight.org/content/repositories/public/</url>
622                     <releases><updatePolicy>never</updatePolicy></releases>
623                     <snapshots><enabled>false</enabled></snapshots>
624                   </repository>
625                 </repositories>
626                 <pluginRepositories>
627                   <pluginRepository>
628                     <id>opendaylight-plugin-mirror</id>
629                     <name>opendaylight-plugin</name>
630                     <url>https://nexus.opendaylight.org/content/repositories/public/</url>
631                     <releases><updatePolicy>never</updatePolicy></releases>
632                     <snapshots><enabled>false</enabled></snapshots>
633                   </pluginRepository>
634                 </pluginRepositories>
635               </profile>
636               <profile>
637                 <id>file-snapshots</id>
638                 <repositories>
639                   <repository>
640                     <id>file-snapshots</id>
641                     <name>file</name>
642                     <url>file:///tmp/n/</url>
643                     <releases><enabled>false</enabled></releases>
644                   </repository>
645                 </repositories>
646                 <pluginRepositories>
647                   <pluginRepository>
648                     <id>file-plugin-snapshots</id>
649                     <name>file-plugin</name>
650                     <url>file:///tmp/n/</url>
651                     <releases><enabled>false</enabled></releases>
652                   </pluginRepository>
653                 </pluginRepositories>
654               </profile>
655             </profiles>
656             <activeProfiles>
657               <activeProfile>file-snapshots</activeProfile>
658               <activeProfile>opendaylight-release</activeProfile>
659             </activeProfiles>
660           </settings>
661           ' > fake_remotes.xml
662           # Notes: The settings are minimal in order to detect breakage scenarios,
663           # while allowing for the following quirks:
664           # * Some plugins seem to have hardcoded repos, for example check-license looks at repository.apache.org
665           # * Some plugin artifacts (related to surefire) are not downloaded when tests are skipped.
666           # * populate-local-repo looks at oss.sonatype.org and does not store things (like guava) to /tmp/r
667
668 - builder:
669     name: distribution-check-repeat-build
670     # Step five: Repeat the distribution build but with the new settings.
671     # Here, only the project snapshot artifacts deployed to /tmp/n are available,
672     # which faithfully reproduces conditions in later verify-like job runs.
673     # We cannot use --offline, because: "Cannot access file (file:///tmp/n) in offline mode"
674     # This is where SingleFeatureTest is not skipped.
675     # Arguments:
676     #   dist-pom: Relative path to pom file to use. 'distribution/pom.xml' is recommended.
677     builders:
678       - maven-target:
679           maven-version: 'mvn33'
680           pom: '{dist-pom}'
681           goals: |
682               clean install dependency:tree
683               -DoutputFile=dependency_tree.txt -s fake_remotes.xml
684               -Pq
685               -DskipTests=false
686               {mvn-opts}
687           java-opts:
688             - '-Xmx1024m -XX:MaxPermSize=256m -Dmaven.compile.fork=true'