Merge "Add templates Cmake + SonarQube Jenkins plugin"
[releng/global-jjb.git] / jjb / lf-c-cpp-jobs.yaml
1 ---
2 ###############
3 # CMAKE SONAR #
4 ###############
5
6 - lf_cmake_sonar: &lf_cmake_sonar
7     name: lf-cmake-sonar
8
9     ######################
10     # Default parameters #
11     ######################
12
13     branch: master
14     build-days-to-keep: 7
15     build-dir: "$WORKSPACE/target"
16     build-timeout: 15
17     cmake-opts: ""
18     cron: "@daily"
19     disable-job: false
20     git-url: "$GIT_URL/$PROJECT"
21     github-url: "https://github.com"
22     install-prefix: "$BUILD_DIR/output"
23     make-opts: ""
24     pre-build: ""
25     sonar-scanner-version: 3.3.0.1492
26     sonarcloud-api-token: ""
27     sonarcloud-organization: ""
28     sonarcloud-project-key: ""
29     stream: master
30     submodule-recursive: true
31     submodule-timeout: 10
32     submodule-disable: false
33
34     #####################
35     # Job Configuration #
36     #####################
37
38     project-type: freestyle
39     node: "{build-node}"
40     disabled: "{disable-job}"
41
42     properties:
43       - lf-infra-properties:
44           build-days-to-keep: "{build-days-to-keep}"
45
46     parameters:
47       - lf-infra-parameters:
48           project: "{project}"
49           branch: "{branch}"
50           stream: "{stream}"
51           lftools-version: "{lftools-version}"
52       - lf-cmake-parameters:
53           build-dir: "{build-dir}"
54           cmake-opts: "{cmake-opts}"
55           install-prefix: "{install-prefix}"
56           make-opts: "{make-opts}"
57
58     wrappers:
59       - lf-infra-wrappers:
60           build-timeout: "{build-timeout}"
61           jenkins-ssh-credential: "{jenkins-ssh-credential}"
62
63     builders:
64       - lf-infra-pre-build
65       - shell: "{pre-build}"
66       - inject:
67           # Switch this to the sonar wrapper when JJB 2.0 is available
68           properties-content: |
69             SONAR_HOST_URL=https://sonarcloud.io
70             SONAR_SCANNER_VERSION={sonar-scanner-version}
71             PROJECT_KEY={sonarcloud-project-key}
72             PROJECT_ORGANIZATION={sonarcloud-organization}
73             API_TOKEN={sonarcloud-api-token}
74       - shell: !include-raw-escape: ../shell/cmake-sonar.sh
75       - lf-provide-maven-settings-cleanup
76
77     publishers:
78       - lf-infra-publish
79
80 - job-template:
81     name: "{project-name}-cmake-sonar"
82     id: gerrit-cmake-sonar
83     concurrent: false
84     <<: *lf_cmake_sonar
85
86     scm:
87       - lf-infra-gerrit-scm:
88           branch: "$GERRIT_BRANCH"
89           jenkins-ssh-credential: "{jenkins-ssh-credential}"
90           git-url: "{git-url}"
91           refspec: "$GERRIT_REFSPEC"
92           submodule-recursive: "{submodule-recursive}"
93           submodule-timeout: "{submodule-timeout}"
94           submodule-disable: "{submodule-disable}"
95           choosing-strategy: gerrit
96
97     triggers:
98       - timed: "{obj:cron}"
99       - gerrit:
100           server-name: "{gerrit-server-name}"
101           trigger-on:
102             - comment-added-contains-event:
103                 comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
104           projects:
105             - project-compare-type: "ANT"
106               project-pattern: "{project}"
107               branches:
108                 - branch-compare-type: "ANT"
109                   branch-pattern: "**/{branch}"
110
111 - job-template:
112     name: "{project-name}-cmake-sonar"
113     id: github-cmake-sonar
114     concurrent: false
115     <<: *lf_cmake_sonar
116
117     properties:
118       - lf-infra-properties:
119           build-days-to-keep: "{build-days-to-keep}"
120       - github:
121           url: "{github-url}/{github-org}/{project}"
122
123     scm:
124       - lf-infra-github-scm:
125           url: "{git-clone-url}{github-org}/{project}"
126           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
127           branch: "$sha1"
128           submodule-recursive: "{submodule-recursive}"
129           submodule-timeout: "{submodule-timeout}"
130           submodule-disable: "{submodule-disable}"
131           choosing-strategy: default
132           jenkins-ssh-credential: "{jenkins-ssh-credential}"
133
134     triggers:
135       - timed: "{obj:cron}"
136
137 ###################
138 # CMAKE SONARQUBE #
139 ###################
140
141 - lf_cmake_sonarqube: &lf_cmake_sonarqube
142     name: lf-cmake-sonarqube
143
144     ######################
145     # Default parameters #
146     ######################
147
148     archive-artifacts: >
149       **/*.log
150     branch: master # Sonar should always be run on master branch
151     build-days-to-keep: 7
152     build-dir: "$WORKSPACE/build"
153     build-timeout: 15
154     build-wrap-dir: "$WORKSPACE/bw-output"
155     cmake-opts: ""
156     cron: "@weekly"
157     disable-job: false
158     git-url: "$GIT_URL/$PROJECT"
159     github-url: "https://github.com"
160     install-prefix: "$BUILD_DIR/output"
161     make-opts: ""
162     stream: master
163     submodule-recursive: true
164     submodule-timeout: 10
165     submodule-disable: false
166
167     # Sonar properties
168     sonar-additional-args: ""
169     sonar-java-opts: ""
170     sonar-prescan-script: ""
171     sonar-project-file: "sonar-project.properties"
172     sonar-properties: ""
173     sonar-task: ""
174
175     #####################
176     # Job Configuration #
177     #####################
178
179     project-type: freestyle
180     node: "{build-node}"
181     disabled: "{disable-job}"
182
183     properties:
184       - lf-infra-properties:
185           build-days-to-keep: "{build-days-to-keep}"
186
187     wrappers:
188       - lf-infra-wrappers:
189           build-timeout: "{build-timeout}"
190           jenkins-ssh-credential: "{jenkins-ssh-credential}"
191
192     parameters:
193       - lf-infra-parameters:
194           project: "{project}"
195           branch: "{branch}"
196           stream: "{stream}"
197       - lf-cmake-parameters:
198           build-dir: "{build-dir}"
199           cmake-opts: "{cmake-opts}"
200           install-prefix: "{install-prefix}"
201           make-opts: "{make-opts}"
202       - string:
203           name: ARCHIVE_ARTIFACTS
204           default: "{archive-artifacts}"
205           description: Artifacts to archive to the logs server.
206       - string:
207           name: BUILD_WRAP_DIR
208           default: "{build-wrap-dir}"
209           description: SonarQube build wrapper output directory.
210
211     builders:
212       - lf-infra-pre-build
213       - shell: "{sonar-prescan-script}"
214       - shell: !include-raw-escape: ../shell/cmake-sonarqube.sh
215       - lf-infra-sonar:
216           sonar-task: "{sonar-task}"
217           sonar-project-file: "{sonar-project-file}"
218           sonar-properties: "{sonar-properties}"
219           sonar-java-opts: "{sonar-java-opts}"
220           sonar-additional-args: "{sonar-additional-args}"
221
222     publishers:
223       - lf-infra-publish
224
225 - job-template:
226     name: "{project-name}-cmake-sonarqube"
227     id: gerrit-cmake-sonarqube
228     concurrent: false
229     <<: *lf_cmake_sonarqube
230
231     scm:
232       - lf-infra-gerrit-scm:
233           branch: "$GERRIT_BRANCH"
234           jenkins-ssh-credential: "{jenkins-ssh-credential}"
235           git-url: "{git-url}"
236           refspec: "$GERRIT_REFSPEC"
237           submodule-recursive: "{submodule-recursive}"
238           submodule-timeout: "{submodule-timeout}"
239           submodule-disable: "{submodule-disable}"
240           choosing-strategy: default
241
242     triggers:
243       - timed: "{obj:cron}"
244       - gerrit:
245           server-name: "{gerrit-server-name}"
246           trigger-on:
247             - comment-added-contains-event:
248                 comment-contains-value: '^Patch Set\s+\d+:\s+run-sonar\s*$'
249           projects:
250             - project-compare-type: "ANT"
251               project-pattern: "{project}"
252               branches:
253                 - branch-compare-type: "ANT"
254                   branch-pattern: "**/{branch}"
255
256 - job-template:
257     name: "{project-name}-cmake-sonarqube"
258     id: github-cmake-sonarqube
259     concurrent: false
260     <<: *lf_cmake_sonarqube
261
262     scm:
263       - lf-infra-github-scm:
264           branch: "$sha1"
265           jenkins-ssh-credential: "{jenkins-ssh-credential}"
266           url: "{git-clone-url}{github-org}/{project}"
267           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
268           submodule-recursive: "{submodule-recursive}"
269           submodule-timeout: "{submodule-timeout}"
270           submodule-disable: "{submodule-disable}"
271           choosing-strategy: default
272
273     triggers:
274       - github-pull-request:
275           trigger-phrase: "^run-sonar$"
276           only-trigger-phrase: false
277           status-context: "CMake Sonarqube"
278           permit-all: true
279           github-hooks: true
280           white-list-target-branches:
281             - "{branch}"
282
283 ###############
284 # CMAKE STAGE #
285 ###############
286
287 - lf_cmake_stage: &lf_cmake_stage
288     name: lf-cmake-stage
289
290     ######################
291     # Default parameters #
292     ######################
293
294     branch: master
295     build-days-to-keep: 7
296     build-dir: "$WORKSPACE/target"
297     build-timeout: 15
298     cmake-opts: ""
299     cron: "@daily"
300     disable-job: false
301     git-url: "$GIT_URL/$PROJECT"
302     github-url: "https://github.com"
303     install-prefix: "$BUILD_DIR/output"
304     make-opts: ""
305     mvn-global-settings: global-settings
306     pre-build: ""
307     stream: master
308     submodule-recursive: true
309     submodule-timeout: 10
310     submodule-disable: false
311     version: ""
312
313     #####################
314     # Job Configuration #
315     #####################
316
317     project-type: freestyle
318     node: "{build-node}"
319     disabled: "{disable-job}"
320
321     properties:
322       - lf-infra-properties:
323           build-days-to-keep: "{build-days-to-keep}"
324
325     parameters:
326       - lf-infra-parameters:
327           project: "{project}"
328           branch: "{branch}"
329           stream: "{stream}"
330       - lf-cmake-parameters:
331           build-dir: "{build-dir}"
332           cmake-opts: "{cmake-opts}"
333           install-prefix: "{install-prefix}"
334           make-opts: "{make-opts}"
335       - string:
336           name: NEXUS_GROUP_ID
337           default: "{nexus-group-id}"
338           description: "Project Group ID in Nexus to upload to."
339       - string:
340           name: STAGING_PROFILE_ID
341           default: "{staging-profile-id}"
342           description: "Nexus staging profile ID."
343       - string:
344           name: VERSION
345           default: "{version}"
346           description: |
347             (default: '')
348
349             Project version to stage release as. There are 2 methods for
350             using this value:
351
352                 1) Defined explicitly here.
353                 2) Leave this value blank and set /tmp/artifact_version
354
355             Use method 2 in conjunction with 'pre-build' configuration to
356             generate the artifact_version automatically from files in the
357             project's repository. For example with pre-build script:
358
359             #!/bin/bash
360             MAJOR_VERSION="$(grep 'set(OCIO_VERSION_MAJOR' CMakeLists.txt \
361                 | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
362             MINOR_VERSION="$(grep 'set(OCIO_VERSION_MINOR' CMakeLists.txt \
363                 | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
364             PATCH_VERSION="$(grep 'set(OCIO_VERSION_PATCH' CMakeLists.txt \
365                 | awk '{{print $NF}}' | awk -F')' '{{print $1}}')"
366             echo "${{MAJOR_VERSION}}.${{MINOR_VERSION}}.${{PATCH_VERSION}}" > /tmp/artifact_version
367
368     wrappers:
369       - lf-infra-wrappers:
370           build-timeout: "{build-timeout}"
371           jenkins-ssh-credential: "{jenkins-ssh-credential}"
372
373     builders:
374       - lf-infra-pre-build
375       - lf-provide-maven-settings:
376           global-settings-file: "{mvn-global-settings}"
377           settings-file: "{mvn-settings}"
378       - lf-infra-create-netrc:
379           server-id: staging
380       - shell: "{pre-build}"
381       - shell: !include-raw-escape: ../shell/cmake-build.sh
382       - shell: !include-raw-escape: ../shell/cmake-stage.sh
383       - lf-provide-maven-settings-cleanup
384
385     publishers:
386       - lf-infra-publish
387
388 - job-template:
389     name: "{project-name}-cmake-stage-{stream}"
390     id: gerrit-cmake-stage
391     concurrent: true
392     <<: *lf_cmake_stage
393
394     scm:
395       - lf-infra-gerrit-scm:
396           branch: "$GERRIT_BRANCH"
397           jenkins-ssh-credential: "{jenkins-ssh-credential}"
398           git-url: "{git-url}"
399           refspec: "$GERRIT_REFSPEC"
400           submodule-recursive: "{submodule-recursive}"
401           submodule-timeout: "{submodule-timeout}"
402           submodule-disable: "{submodule-disable}"
403           choosing-strategy: gerrit
404
405     triggers:
406       - timed: "{obj:cron}"
407       - gerrit:
408           server-name: "{gerrit-server-name}"
409           trigger-on:
410             - comment-added-contains-event:
411                 comment-contains-value: '^Patch Set\s+\d+:\s+stage-release\s*$'
412           projects:
413             - project-compare-type: "ANT"
414               project-pattern: "{project}"
415               branches:
416                 - branch-compare-type: "ANT"
417                   branch-pattern: "**/{branch}"
418
419 - job-template:
420     name: "{project-name}-cmake-stage-{stream}"
421     id: github-cmake-stage
422     concurrent: true
423     <<: *lf_cmake_stage
424
425     properties:
426       - lf-infra-properties:
427           build-days-to-keep: "{build-days-to-keep}"
428       - github:
429           url: "{github-url}/{github-org}/{project}"
430
431     scm:
432       - lf-infra-github-scm:
433           url: "{git-clone-url}{github-org}/{project}"
434           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
435           branch: "$sha1"
436           submodule-recursive: "{submodule-recursive}"
437           submodule-timeout: "{submodule-timeout}"
438           submodule-disable: "{submodule-disable}"
439           choosing-strategy: default
440           jenkins-ssh-credential: "{jenkins-ssh-credential}"
441
442     triggers:
443       - timed: "{obj:cron}"
444       - github-pull-request:
445           trigger-phrase: "^(stage-release)$"
446           only-trigger-phrase: true
447           status-context: "CMake Stage"
448           permit-all: true
449           github-hooks: true
450           white-list-target-branches:
451             - "{branch}"
452
453 ################
454 # CMAKE VERIFY #
455 ################
456
457 - lf_cmake_verify: &lf_cmake_verify
458     name: lf-cmake-verify
459
460     ######################
461     # Default parameters #
462     ######################
463
464     branch: master
465     build-days-to-keep: 7
466     build-dir: "$WORKSPACE/target"
467     build-timeout: 15
468     cmake-opts: ""
469     disable-job: false
470     git-url: "$GIT_URL/$PROJECT"
471     github-url: "https://github.com"
472     install-prefix: "$BUILD_DIR/output"
473     make-opts: ""
474     pre-build: ""
475     stream: master
476     submodule-recursive: true
477     submodule-timeout: 10
478     submodule-disable: false
479
480     gerrit_verify_triggers:
481       - patchset-created-event:
482           exclude-drafts: true
483           exclude-trivial-rebase: false
484           exclude-no-code-change: false
485       - draft-published-event
486       - comment-added-contains-event:
487           comment-contains-value: '^Patch Set\s+\d+:\s+(recheck|reverify)\s*$'
488
489     gerrit_trigger_file_paths:
490       - compare-type: REG_EXP
491         pattern: ".*"
492
493     # github_included_regions MUST match gerrit_trigger_file_paths
494     github_included_regions:
495       - ".*"
496
497     #####################
498     # Job Configuration #
499     #####################
500
501     project-type: freestyle
502     node: "{build-node}"
503     disabled: "{disable-job}"
504
505     properties:
506       - lf-infra-properties:
507           build-days-to-keep: "{build-days-to-keep}"
508
509     parameters:
510       - lf-infra-parameters:
511           project: "{project}"
512           branch: "{branch}"
513           stream: "{stream}"
514       - lf-cmake-parameters:
515           build-dir: "{build-dir}"
516           cmake-opts: "{cmake-opts}"
517           install-prefix: "{install-prefix}"
518           make-opts: "{make-opts}"
519
520     wrappers:
521       - lf-infra-wrappers:
522           build-timeout: "{build-timeout}"
523           jenkins-ssh-credential: "{jenkins-ssh-credential}"
524
525     builders:
526       - shell: "{pre-build}"
527       - shell: !include-raw-escape: ../shell/cmake-build.sh
528
529     publishers:
530       - lf-infra-publish
531
532 - job-template:
533     name: "{project-name}-cmake-verify-{stream}"
534     id: gerrit-cmake-verify
535     concurrent: true
536     <<: *lf_cmake_verify
537
538     scm:
539       - lf-infra-gerrit-scm:
540           branch: "$GERRIT_BRANCH"
541           jenkins-ssh-credential: "{jenkins-ssh-credential}"
542           git-url: "{git-url}"
543           refspec: "$GERRIT_REFSPEC"
544           submodule-recursive: "{submodule-recursive}"
545           submodule-timeout: "{submodule-timeout}"
546           submodule-disable: "{submodule-disable}"
547           choosing-strategy: gerrit
548
549     triggers:
550       - gerrit:
551           server-name: "{gerrit-server-name}"
552           trigger-on: "{obj:gerrit_verify_triggers}"
553           projects:
554             - project-compare-type: "ANT"
555               project-pattern: "{project}"
556               branches:
557                 - branch-compare-type: "ANT"
558                   branch-pattern: "**/{branch}"
559               file-paths: "{obj:gerrit_trigger_file_paths}"
560
561 - job-template:
562     name: "{project-name}-cmake-verify-{stream}"
563     id: github-cmake-verify
564     concurrent: true
565     <<: *lf_cmake_verify
566
567     properties:
568       - lf-infra-properties:
569           build-days-to-keep: "{build-days-to-keep}"
570       - github:
571           url: "{github-url}/{github-org}/{project}"
572
573     scm:
574       - lf-infra-github-scm:
575           url: "{git-clone-url}{github-org}/{project}"
576           refspec: "+refs/pull/*:refs/remotes/origin/pr/*"
577           branch: "$sha1"
578           submodule-recursive: "{submodule-recursive}"
579           submodule-timeout: "{submodule-timeout}"
580           submodule-disable: "{submodule-disable}"
581           choosing-strategy: default
582           jenkins-ssh-credential: "{jenkins-ssh-credential}"
583
584     triggers:
585       - github-pull-request:
586           trigger-phrase: "^(recheck|reverify)$"
587           only-trigger-phrase: false
588           status-context: "CMake Verify"
589           permit-all: true
590           github-hooks: true
591           included-regions: "{obj:github_included_regions}"
592           white-list-target-branches:
593             - "{branch}"