jjb: lava: Rework baremetal jobs and introduce trigger job
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 21 Dec 2017 21:07:39 +0000 (16:07 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 9 Jan 2018 03:19:31 +0000 (22:19 -0500)
Previously, each job was tracking jobs in its branches of interest in an
odd combination Jenkins CMS trigger and Bash script. It readability was
low and maintainability even lower.

This commit implements those features using the Groovy script console.

Lava jobs are now taking commit IDs as parameter. The trigger job checks
the status of each git branches of interest and launch the right jobs
for each new changes in those branches using the right commit IDs.

The goal of these changes is to increase maintainability and to regroup
the lava jobs under a single umbrella Jenkins project.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
jobs/lttng-baremetal-tests.yaml
scripts/lttng-baremetal-tests/baremetal-trigger.groovy [new file with mode: 0644]
scripts/lttng-baremetal-tests/generate-properties-master.sh

index 3f055b0defe84518749d609e299ab130cdd87af6..cf2692d90e6e6613f8d49e515dde98d16e1327ef 100644 (file)
@@ -1,11 +1,77 @@
+---
+## Anchors
+- lttng_baremetal_tests_parameters_defaults: &lttng_baremetal_tests_parameters_defaults
+    name: 'lttng_baremetal_tests_parameters_defaults'
+    parameters:
+      - string:
+          name: 'tools_commit_id'
+          default: ''
+          description: 'The lttng-tools commit id to build.'
+      - string:
+          name: 'modules_commit_id'
+          default: ''
+          description: 'The lttng-modules commit id to build.'
+      - string:
+          name: 'ust_commit_id'
+          default: ''
+          description: 'The lttng-ust commit id to build.'
+      - string:
+          name: 'kernel_tag_id'
+          default: ''
+          description: 'The linux kernel git tag to build against.'
+      - string:
+          name: 'kernel_repo'
+          default: 'git://git-mirror.internal.efficios.com/kernel/stable/linux-stable.git'
+          description: 'Linux kernel git repo to checkout the kernel id'
+      - string:
+          name: 'tools_repo'
+          default: 'https://github.com/lttng/lttng-tools.git'
+          description: 'LTTng-Tools git repo to checkout the tools id'
+      - string:
+          name: 'modules_repo'
+          default: 'https://github.com/lttng/lttng-modules.git'
+          description: 'LTTng-Modules git repo to checkout the Modules id'
+      - string:
+          name: 'ust_repo'
+          default: 'https://github.com/lttng/lttng-ust.git'
+          description: 'LTTng-UST git repo to checkout the UST id'
+
+- lttng_baremetal_tests_publisher_defaults: &lttng_baremetal_tests_publisher_defaults
+    name: 'lttng_baremetal_tests_publisher_defaults'
+    publishers:
+      - email-ext:
+          recipients: '{obj:email_to}'
+          reply-to: ci-notification@lists.lttng.org
+          always: false
+          unstable: false
+          first-failure: true
+          first-unstable: true
+          not-built: false
+          aborted: false
+          regression: false
+          failure: false
+          second-failure: false
+          improvement: false
+          still-failing: false
+          success: false
+          fixed: false
+          fixed-unhealthy: true
+          still-unstable: false
+          pre-build: false
+          matrix-trigger: only-parent
+          send-to:
+            - recipients
+      - workspace-cleanup
+
+## Defaults
 - defaults:
     name: baremetal_benchmarks
     description: |
-      Runs baremetal kernel tests over different combination of kernel and lttng configurations.
+      Runs baremetal kernel benchmarks over different combination of kernel and lttng configurations.
+    project-type: freestyle
+    node: 'x86-64'
 
-    triggers:
-      - pollscm:
-          cron: "H * * * 1-5"
+    <<: *lttng_baremetal_tests_parameters_defaults
 
     properties:
       - build-discarder:
@@ -16,8 +82,6 @@
           categories:
             - 'baremetal-tests'
 
-    project-type: freestyle
-    node: 'x86-64'
     wrappers:
       - workspace-cleanup
       - timestamps
               variable: identity_file
       - inject:
           properties-content: |
-            TOOLS_BRANCH={lttngversion}
-            UST_BRANCH={lttngversion}
             BUILD_DEVICE=baremetal
 
+    builders:
+      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/generate-properties-master.sh
+      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/inject-ssh-commands.sh
+      - trigger-builds:
+        - project: "build_kernel_PARAM"
+          property-file: 'properties.txt'
+          block: true
+      - inject:
+          properties-file: properties.txt
+      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/run-baremetal-benchmarks.sh
+      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/summarize-results.sh
+
     publishers:
       - archive:
           artifacts: '*.png,*.csv'
           includes: '*.png'
       - workspace-cleanup
 
-    scm:
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-tools.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-tools
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-modules.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-modules
-      - git:
-          url: git://git-mirror.internal.efficios.com/kernel/stable/linux-stable.git
-          branches:
-            - "{kversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/linux
-
-    builders:
-      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/generate-properties-master.sh
-      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/inject-ssh-commands.sh
-      - trigger-builds:
-        - project: "build_kernel_PARAM"
-          property-file: 'properties.txt'
-          block: true
-      - inject:
-          properties-file: properties.txt
-      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/run-baremetal-benchmarks.sh
-      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/summarize-results.sh
-
-
 - defaults:
     name: vm_tests
     description: |
-      Runs baremetal kernel tests over different combination of kernel and lttng configurations.
+      Runs virtual machine kernel tests over different combination of kernel and lttng configurations.
     project-type: freestyle
     node: 'master'
+    <<: *lttng_baremetal_tests_parameters_defaults
 
     properties:
       - build-discarder:
           categories:
             - 'kvm-tests'
 
-    triggers:
-      - pollscm:
-          cron: "H * * * 1-5"
-
     wrappers:
       - workspace-cleanup
       - timestamps
       - inject:
           properties-content: |
             BUILD_DEVICE=kvm
-            TOOLS_BRANCH={lttngversion}
-            UST_BRANCH={lttngversion}
-
-    scm:
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-tools.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-tools
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-modules.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-modules
-      - git:
-          url: git://git-mirror.internal.efficios.com/kernel/stable/linux-stable.git
-          branches:
-            - "{kversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/linux
-
-    publishers:
-      - email-ext:
-          recipients: '{obj:email_to}'
-          reply-to: ci-notification@lists.lttng.org
-          always: false
-          unstable: false
-          first-failure: true
-          first-unstable: true
-          not-built: false
-          aborted: false
-          regression: false
-          failure: false
-          second-failure: false
-          improvement: false
-          still-failing: false
-          success: false
-          fixed: false
-          fixed-unhealthy: true
-          still-unstable: false
-          pre-build: false
-          matrix-trigger: only-parent
-          send-to:
-            - recipients
-      - workspace-cleanup
 
     builders:
       - shell: !include-raw-escape: scripts/lttng-baremetal-tests/generate-properties-master.sh
           properties-file: properties.txt
       - shell: !include-raw-escape: scripts/lttng-baremetal-tests/run-kvm-tests.sh
 
+    <<: *lttng_baremetal_tests_publisher_defaults
 
 - defaults:
-    name: vm_tests_kmainline
-    defaults: vm_tests
+    name: vm_tests_fuzzing
+    description: |
+      Runs virtual machine fuzzing tests over different combination of kernel and lttng configurations.
+    project-type: freestyle
+    node: 'master'
+    <<: *lttng_baremetal_tests_parameters_defaults
 
-    triggers:
-      - pollscm:
-          cron: "0 1 * * 1-5"
+    properties:
+      - build-discarder:
+          num-to-keep: 10
+      - throttle:
+          max-total: 2
+          option: 'category'
+          categories:
+            - 'kvm-tests'
 
     wrappers:
       - workspace-cleanup
               variable: LAVA_JENKINS_TOKEN
       - inject:
           properties-content: |
-            TOOLS_BRANCH={lttngversion}
-            MODULES_BRANCH={lttngversion}
-            UST_BRANCH={lttngversion}
-            BUILD_DEVICE=baremetal
-    scm:
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-tools.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-tools
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-modules.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-modules
-      - git:
-          url: git://git-mirror.internal.efficios.com/kernel/torvalds/linux.git
-          refspec: "+refs/tags/*:refs/remotes/origin/tags/*"
-          branches:
-            - "master"
-          fastpoll: true
-          basedir: src/linux
+            BUILD_DEVICE=kvm
+
+    builders:
+      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/generate-properties-master.sh
+      - trigger-builds:
+        - project: "build_kernel_PARAM"
+          property-file: 'properties.txt'
+          block: true
+      - inject:
+          properties-file: properties.txt
+      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/run-kvm-fuzzing-tests.sh
 
+    <<: *lttng_baremetal_tests_publisher_defaults
 
 - defaults:
     name: baremetal_tests
     project-type: freestyle
     node: 'master'
 
+    <<: *lttng_baremetal_tests_parameters_defaults
+
     properties:
       - build-discarder:
           num-to-keep: 10
           categories:
             - 'baremetal-tests'
 
-    triggers:
-      - pollscm:
-          cron: "H * * * 1-5"
-
     wrappers:
       - workspace-cleanup
       - timestamps
               variable: LAVA_JENKINS_TOKEN
       - inject:
           properties-content: |
-            UST_BRANCH={lttngversion}
             BUILD_DEVICE=baremetal
 
-    scm:
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-tools.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-tools
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-modules.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-modules
-      - git:
-          url: git://git-mirror.internal.efficios.com/kernel/stable/linux-stable.git
-          branches:
-            - "{kversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/linux
-
-    publishers:
-      - workspace-cleanup
-      - email-ext:
-          recipients: '{obj:email_to}'
-          reply-to: ci-notification@lists.lttng.org
-          always: false
-          unstable: false
-          first-failure: true
-          first-unstable: true
-          not-built: false
-          aborted: false
-          regression: false
-          failure: false
-          second-failure: false
-          improvement: false
-          still-failing: false
-          success: false
-          fixed: false
-          fixed-unhealthy: true
-          still-unstable: false
-          pre-build: false
-          matrix-trigger: only-parent
-          send-to:
-            - recipients
-
     builders:
       - shell: !include-raw-escape: scripts/lttng-baremetal-tests/generate-properties-master.sh
       - trigger-builds:
           properties-file: properties.txt
       - shell: !include-raw-escape: scripts/lttng-baremetal-tests/run-baremetal-tests.sh
 
+    <<: *lttng_baremetal_tests_publisher_defaults
 
+## Templates
 - job-template:
-    name: baremetal_benchmarks_k{kversion}_l{lttngversion}
-    defaults: baremetal_benchmarks
-- job-template:
-    name: vm_tests_k{kversion}_l{lttngversion}
-    defaults: vm_tests
-- job-template:
-    name: baremetal_tests_k{kversion}_l{lttngversion}
-    defaults: baremetal_tests
-
-
-# Canary jobs are made to confirm that the whole Lava pipeline is working.
-# They are scheduled once a day always on the same (LTTng, Kernel) code. If any
-# of those jobs fails, it means that there is an issue with the configuration
-- job-template:
-    name: baremetal_tests_k{kversion}_l{lttngversion}_canary
-    defaults: baremetal_tests
-    triggers:
-      - timed: "0 1 * * 1-5"
-- job-template:
-    name: vm_tests_k{kversion}_l{lttngversion}_canary
-    defaults: vm_tests
-    triggers:
-      - timed: "0 1 * * 1-5"
-- job-template:
-    name: baremetal_benchmarks_k{kversion}_l{lttngversion}_canary
-    defaults: baremetal_benchmarks
-    triggers:
-      - timed: "0 1 * * 1-5"
-- job-template:
-    name: vm_tests_kmainline_l{lttngversion}
-    defaults: vm_tests_kmainline
-
-- job-template:
-    name: vm_tests_fuzzing_kmainline_l{lttngversion}
-    defaults: vm_tests_kmainline
-
-    builders:
-      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/generate-properties-master.sh
-      - trigger-builds:
-        - project: "build_kernel_PARAM"
-          property-file: 'properties.txt'
-          block: true
-      - inject:
-          properties-file: properties.txt
-      - shell: !include-raw-escape: scripts/lttng-baremetal-tests/run-kvm-fuzzing-tests.sh
-
-- job-template:
-    name: baremetal_tests_kmainline_l{lttngversion}
-    defaults: baremetal_tests
-
-    triggers:
-      - pollscm:
-          cron: "0 1 * * 1-5"
-
-    wrappers:
-      - workspace-cleanup
-      - timestamps
-      - ansicolor
-      - credentials-binding:
-          - text:
-              credential-id: jenkins_lava_key
-              variable: LAVA_JENKINS_TOKEN
-      - inject:
-          properties-content: |
-            TOOLS_BRANCH={lttngversion}
-            MODULES_BRANCH={lttngversion}
-            UST_BRANCH={lttngversion}
-            BUILD_DEVICE=baremetal
-
-    scm:
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-tools.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-tools
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-modules.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-modules
-      - git:
-          url: git://git-mirror.internal.efficios.com/kernel/torvalds/linux.git
-          refspec: "+refs/tags/*:refs/remotes/origin/tags/*"
-          branches:
-            - "master"
-          fastpoll: true
-          basedir: src/linux
-
-
-- job-template:
-    name: baremetal_benchmarks_kmainline_l{lttngversion}
-    defaults: baremetal_benchmarks
-
-    triggers:
-      - pollscm:
-          cron: "0 1 * * 1-5"
-
-    wrappers:
-      - workspace-cleanup
-      - timestamps
-      - ansicolor
-      - credentials-binding:
-          - text:
-              credential-id: jenkins_lava_key
-              variable: LAVA_JENKINS_TOKEN
-          - file:
-              credential-id: system_tests_storage_key
-              variable: identity_file
-      - inject:
-          properties-content: |
-            TOOLS_BRANCH={lttngversion}
-            MODULES_BRANCH={lttngversion}
-            UST_BRANCH={lttngversion}
-            BUILD_DEVICE=baremetal
-
-    scm:
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-tools.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-tools
-      - git:
-          url: git://git-mirror.internal.efficios.com/lttng/lttng-modules.git
-          branches:
-            - "{lttngversion}"
-          shallow-clone: true
-          skip-tag: true
-          fastpoll: true
-          basedir: src/lttng-modules
-      - git:
-          url: git://git-mirror.internal.efficios.com/kernel/torvalds/linux.git
-          refspec: "+refs/tags/*:refs/remotes/origin/tags/*"
-          branches:
-            - "master"
-          fastpoll: true
-          basedir: src/linux
-
-
-- job:
     name: build_kernel_PARAM
     description: |
       Builds a Linux Kernel and LTTng Modules if necessary
     publishers:
       - workspace-cleanup
 
+- job-template:
+    name: baremetal_ALL_trigger
+    description: |
+      This job will trigger the build of jobs when a new tag is push specific
+      tracked Linux branches and new commits on LTTng tracked branches
+
+    project-type: freestyle
+    node: 'master'
+
+    properties:
+      - build-discarder:
+          num-to-keep: 10
+
+    triggers:
+      - timed: "@daily"
+
+    wrappers:
+      - timestamps
+      - ansicolor
+
+    builders:
+      - system-groovy:
+         command:
+           !include-raw-escape: scripts/lttng-baremetal-tests/baremetal-trigger.groovy
+
+    <<: *lttng_baremetal_tests_publisher_defaults
+
+- job-template:
+    name: baremetal_benchmarks_k{kversion}_l{lttngversion}
+    defaults: baremetal_benchmarks
+- job-template:
+    name: vm_tests_k{kversion}_l{lttngversion}
+    defaults: vm_tests
+- job-template:
+    name: baremetal_tests_k{kversion}_l{lttngversion}
+    defaults: baremetal_tests
+
+- job-template:
+    name: vm_tests_fuzzing_k{kversion}_l{lttngversion}
+    defaults: vm_tests_fuzzing
+
+# Canary jobs are made to confirm that the whole Lava pipeline is working.
+# They are scheduled once a day always on the same (LTTng, Kernel) code. If any
+# of those jobs fails, it means that there is an issue with the configuration
+- job-template:
+    name: baremetal_benchmarks_canary
+    defaults: baremetal_benchmarks
+
+- job-template:
+    name: baremetal_tests_canary
+    defaults: baremetal_tests
+
+- job-template:
+    name: vm_tests_canary
+    defaults: vm_tests
 
 ## Project
 - project:
-    name: lttng-kernel-tests
+    name: lttng-baremetal-tests
     email_to: 'ci-notification@lists.lttng.org, cc:francis.deslauriers@efficios.com'
     kversion:
+      - master
       - linux-4.4.y
       - linux-4.9.y
-      - v4.8.1
     lttngversion:
       - master
       - stable-2.9
       - 'baremetal_tests_k{kversion}_l{lttngversion}'
 
 - project:
-    name: lttng-kernel-tests-oldkernel
+    name: lttng-baremetal-tests-oldkernel
     email_to: 'ci-notification@lists.lttng.org, cc:francis.deslauriers@efficios.com'
     kversion:
       - linux-3.18.y
       - 'baremetal_benchmarks_k{kversion}_l{lttngversion}':
 
 - project:
-    name: lttng-kernel-tests-canary
+    name: lttng-baremetal-tests-canary
     email_to: 'ci-notification@lists.lttng.org, cc:francis.deslauriers@efficios.com'
-    kversion:
-      - v4.4.9
-    lttngversion:
-      - v2.8.1
     jobs:
-      - 'vm_tests_k{kversion}_l{lttngversion}_canary'
-      - 'baremetal_tests_k{kversion}_l{lttngversion}_canary'
-      - 'baremetal_benchmarks_k{kversion}_l{lttngversion}_canary'
+      - 'vm_tests_canary'
+      - 'baremetal_tests_canary'
+      - 'baremetal_benchmarks_canary'
 
 - project:
-    name: lttng-kernel-tests-mainline
-    lttngversion:
-      - master
+    name: lttng-baremetal-fuzzing-tests
+    email_to: 'ci-notification@lists.lttng.org, cc:francis.deslauriers@efficios.com'
+    kversion: master
+    lttngversion: master
+    jobs:
+      - 'vm_tests_fuzzing_k{kversion}_l{lttngversion}'
+- project:
+    name: lttng-baremetal-general
     email_to: 'ci-notification@lists.lttng.org, cc:francis.deslauriers@efficios.com'
     jobs:
-      - 'vm_tests_kmainline_l{lttngversion}'
-      - 'vm_tests_fuzzing_kmainline_l{lttngversion}'
-      - 'baremetal_tests_kmainline_l{lttngversion}'
-      - 'baremetal_benchmarks_kmainline_l{lttngversion}'
+      - 'build_kernel_PARAM'
+      - 'baremetal_ALL_trigger'
diff --git a/scripts/lttng-baremetal-tests/baremetal-trigger.groovy b/scripts/lttng-baremetal-tests/baremetal-trigger.groovy
new file mode 100644 (file)
index 0000000..394227c
--- /dev/null
@@ -0,0 +1,462 @@
+/**
+ * Copyright (C) 2017 - Francis Deslauriers <francis.deslauriers@efficios.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import hudson.console.HyperlinkNote
+import hudson.model.*
+import java.io.File
+import org.eclipse.jgit.api.Git
+import org.eclipse.jgit.lib.Ref
+
+class InvalidKVersionException extends Exception {
+  public InvalidKVersionException(String message) {
+    super(message)
+  }
+}
+
+class EmptyKVersionException extends Exception {
+  public EmptyKVersionException(String message) {
+    super(message)
+  }
+}
+
+class VanillaKVersion implements Comparable<VanillaKVersion> {
+
+  Integer major = 0
+  Integer majorB = 0
+  Integer minor = 0
+  Integer patch = 0
+  Integer rc = Integer.MAX_VALUE
+  Boolean inStable = false;
+
+  VanillaKVersion() {}
+
+  VanillaKVersion(version) {
+    this.parse(version)
+  }
+
+  static VanillaKVersion minKVersion() {
+    return new VanillaKVersion("v0.0.0")
+  }
+
+  static VanillaKVersion maxKVersion() {
+    return new VanillaKVersion("v" + Integer.MAX_VALUE + ".0.0")
+  }
+
+  static VanillaKVersion factory(version) {
+    return new VanillaKVersion(version)
+  }
+
+  def parse(version) {
+    this.major = 0
+    this.majorB = 0
+    this.minor = 0
+    this.patch = 0
+    this.rc = Integer.MAX_VALUE
+
+    if (!version) {
+      throw new EmptyKVersionException("Empty kernel version")
+    }
+
+    def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/
+    if (!match) {
+      throw new InvalidKVersionException("Invalid kernel version: ${version}")
+    }
+
+    Integer offset = 0;
+
+    // Major
+    this.major = Integer.parseInt(match.group(1))
+    if (this.major <= 2) {
+      offset = 2
+      this.majorB = Integer.parseInt(match.group(2))
+    }
+
+    // Minor
+    if (match.group(2 + offset) != null) {
+      this.minor = Integer.parseInt(match.group(2 + offset))
+    }
+
+    // Patch level
+    if (match.group(4 + offset) != null) {
+      this.patch = Integer.parseInt(match.group(4 + offset))
+      this.inStable = true
+    }
+
+    // RC
+    if (match.group(8) != null) {
+      this.rc = Integer.parseInt(match.group(8))
+    }
+  }
+
+  Boolean isInStableBranch() {
+    return this.inStable
+  }
+
+  // Return true if both version are of the same stable branch
+  Boolean isSameStable(VanillaKVersion o) {
+    if (this.major != o.major) {
+      return false
+    }
+    if (this.majorB != o.majorB) {
+      return false
+    }
+    if (this.minor != o.minor) {
+      return false
+    }
+
+    return true
+  }
+
+  @Override int compareTo(VanillaKVersion o) {
+    if (this.major != o.major) {
+      return Integer.compare(this.major, o.major)
+    }
+    if (this.majorB != o.majorB) {
+      return Integer.compare(this.majorB, o.majorB)
+    }
+    if (this.minor != o.minor) {
+      return Integer.compare(this.minor, o.minor)
+    }
+    if (this.patch != o.patch) {
+      return Integer.compare(this.patch, o.patch)
+    }
+    if (this.rc != o.rc) {
+      return Integer.compare(this.rc, o.rc)
+    }
+
+    // Same version
+    return 0;
+  }
+
+  String toString() {
+    String vString = "v${this.major}"
+
+    if (this.majorB > 0) {
+      vString = vString.concat(".${this.majorB}")
+    }
+
+    vString = vString.concat(".${this.minor}")
+
+    if (this.patch > 0) {
+      vString = vString.concat(".${this.patch}")
+    }
+
+    if (this.rc > 0 && this.rc < Integer.MAX_VALUE) {
+      vString = vString.concat("-rc${this.rc}")
+    }
+    return vString
+  }
+}
+
+class RunConfiguration {
+  def linuxBranch
+  def linuxTagId
+  def lttngBranch
+  def lttngModulesCommitId
+  def lttngToolsCommitId
+  def lttngUstCommitId
+  RunConfiguration(linuxBranch, linuxTagId, lttngBranch, lttngToolsCommitId,
+                  lttngModulesCommitId, lttngUstCommitId) {
+    this.linuxBranch = linuxBranch
+    this.linuxTagId = linuxTagId
+    this.lttngBranch = lttngBranch
+    this.lttngModulesCommitId = lttngModulesCommitId
+    this.lttngToolsCommitId = lttngToolsCommitId
+    this.lttngUstCommitId = lttngUstCommitId
+  }
+
+  String toString() {
+    return "${this.linuxBranch}:{${this.linuxTagId}}, ${this.lttngBranch}:{${this.lttngModulesCommitId}, ${this.lttngToolsCommitId}, ${this.lttngUstCommitId}}"
+  }
+}
+
+def LoadPreviousIdsFromWorkspace = { ondiskpath ->
+  def previousIds = []
+  try {
+    File myFile = new File(ondiskpath);
+    def input = new ObjectInputStream(new FileInputStream(ondiskpath))
+    previousIds = input.readObject()
+    input.close()
+  } catch (all) {
+    println("Failed to load previous ids from disk.")
+  }
+  return previousIds
+}
+
+def saveCurrentIdsToWorkspace = { currentIds, ondiskpath ->
+  try {
+    File myFile = new File(ondiskpath);
+    myFile.createNewFile();
+    def out = new ObjectOutputStream(new FileOutputStream(ondiskpath))
+    out.writeObject(currentIds)
+    out.close()
+  } catch (all) {
+    println("Failed to save previous ids from disk.")
+  }
+}
+
+def GetHeadCommits = { remoteRepo, branchesOfInterest ->
+  def remoteHeads = [:]
+  def remoteHeadRefs = Git.lsRemoteRepository()
+                          .setTags(false)
+                          .setHeads(true)
+                          .setRemote(remoteRepo).call()
+
+  remoteHeadRefs.each {
+    def branch = it.getName().replaceAll('refs/heads/', '')
+    if (branchesOfInterest.contains(branch))
+      remoteHeads[branch] = it.getObjectId().name()
+  }
+
+  return remoteHeads
+}
+
+def GetTagIds = { remoteRepo ->
+  def remoteTags = [:]
+  def remoteTagRefs = Git.lsRemoteRepository()
+                         .setTags(true)
+                         .setHeads(false)
+                         .setRemote(remoteRepo).call()
+
+  remoteTagRefs.each {
+    // Exclude release candidate tags
+    if (!it.getName().contains('-rc')) {
+      remoteTags[it.getName().replaceAll('refs/tags/', '')] = it.getObjectId().name()
+    }
+  }
+
+  return remoteTags
+}
+
+def GetLastTagOfBranch = { tagRefs, branch ->
+  def tagVersions = tagRefs.collect {new VanillaKVersion(it.key)}
+  def currMax = new VanillaKVersion('v0.0.0');
+  if (!branch.contains('master')){
+    def targetVersion = new VanillaKVersion(branch.replaceAll('linux-', 'v').replaceAll('.y', ''))
+    tagVersions.each {
+      if (it.isSameStable(targetVersion)) {
+        if (currMax < it) {
+          currMax = it;
+        }
+      }
+    }
+  } else {
+    tagVersions.each {
+      if (!it.isInStableBranch() && currMax < it) {
+        currMax = it;
+      }
+    }
+  }
+  return currMax.toString()
+}
+
+// Returns the latest tags of each of the branches passed in the argument
+def GetLastTagIds = { remoteRepo, branchesOfInterest ->
+  def remoteHeads = GetHeadCommits(remoteRepo, branchesOfInterest)
+  def remoteTagRefs = GetTagIds(remoteRepo)
+  def remoteLastTagCommit = [:]
+
+  remoteTagRefs = remoteTagRefs.findAll { !it.key.contains("v2.") }
+  branchesOfInterest.each {
+    remoteLastTagCommit[it] = remoteTagRefs[GetLastTagOfBranch(remoteTagRefs, it)]
+  }
+
+  return remoteLastTagCommit
+}
+
+def CraftJobName = { jobType, runConfig ->
+  return "${jobType}_k${runConfig.linuxBranch}_l${runConfig.lttngBranch}"
+}
+
+def LaunchJob = { jobName, runConfig ->
+  def job = Hudson.instance.getJob(jobName)
+  def params = []
+  for (paramdef in job.getProperty(ParametersDefinitionProperty.class).getParameterDefinitions()) {
+    params += paramdef.getDefaultParameterValue();
+  }
+
+  params.add(new StringParameterValue('tools_commit_id', runConfig.lttngToolsCommitId))
+  params.add(new StringParameterValue('modules_commit_id', runConfig.lttngModulesCommitId))
+  params.add(new StringParameterValue('ust_commit_id', runConfig.lttngUstCommitId))
+  params.add(new StringParameterValue('kernel_tag_id', runConfig.linuxTagId))
+  job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(params))
+  println "Launching job: ${HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)}"
+}
+
+def jobTypes = ['baremetal_tests', 'vm_tests', 'baremetal_benchmarks']
+final String toolsRepo = "https://github.com/lttng/lttng-tools.git"
+final String modulesRepo = "https://github.com/lttng/lttng-modules.git"
+final String ustRepo = "https://github.com/lttng/lttng-ust.git"
+final String linuxRepo = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git"
+
+final String toolsOnDiskPath = build.getEnvironment(listener).get('WORKSPACE') + "/on-disk-tools-ref"
+final String modulesOnDiskPath = build.getEnvironment(listener).get('WORKSPACE') + "/on-disk-modules-ref"
+final String ustOnDiskPath = build.getEnvironment(listener).get('WORKSPACE') + "/on-disk-ust-ref"
+final String linuxOnDiskPath = build.getEnvironment(listener).get('WORKSPACE') + "/on-disk-linux-ref"
+
+def recentLttngBranchesOfInterest = ['master', 'stable-2.10', 'stable-2.9']
+def recentLinuxBranchesOfInterest = ['master', 'linux-4.9.y', 'linux-4.4.y']
+
+def legacyLttngBranchesOfInterest = ['stable-2.7']
+def legacyLinuxBranchesOfInterest = ['linux-3.18.y', 'linux-4.4.y']
+
+// Generate configurations of interest
+def configurationOfInterest = [] as Set
+
+recentLttngBranchesOfInterest.each { lttngBranch ->
+  recentLinuxBranchesOfInterest.each { linuxBranch ->
+    configurationOfInterest.add([lttngBranch, linuxBranch])
+  }
+}
+
+legacyLttngBranchesOfInterest.each { lttngBranch ->
+  legacyLinuxBranchesOfInterest.each { linuxBranch ->
+    configurationOfInterest.add([lttngBranch, linuxBranch])
+  }
+}
+
+def lttngBranchesOfInterest = recentLttngBranchesOfInterest + legacyLttngBranchesOfInterest
+def linuxBranchesOfInterest = recentLinuxBranchesOfInterest + legacyLinuxBranchesOfInterest
+
+// For Linux branches, we look for new non-RC tags
+def toolsHeadCommits = GetHeadCommits(toolsRepo, lttngBranchesOfInterest)
+def modulesHeadCommits = GetHeadCommits(modulesRepo, lttngBranchesOfInterest)
+def ustHeadCommits = GetHeadCommits(ustRepo, lttngBranchesOfInterest)
+
+// For LTTng branches, we look for new commits
+def linuxLastTagIds = GetLastTagIds(linuxRepo, linuxBranchesOfInterest)
+
+// Load previously build Linux tag ids
+def oldLinuxTags = LoadPreviousIdsFromWorkspace(linuxOnDiskPath) as Set
+
+// Load previously built LTTng commit ids
+def oldToolsHeadCommits = LoadPreviousIdsFromWorkspace(toolsOnDiskPath) as Set
+def oldModulesHeadCommits = LoadPreviousIdsFromWorkspace(modulesOnDiskPath) as Set
+def oldUstHeadCommits = LoadPreviousIdsFromWorkspace(ustOnDiskPath) as Set
+
+def newOldLinuxTags = oldLinuxTags
+def newOldToolsHeadCommits = oldToolsHeadCommits
+def newOldModulesHeadCommits = oldModulesHeadCommits
+def newOldUstHeadCommits = oldUstHeadCommits
+
+def canaryRunConfigs = [] as Set
+canaryRunConfigs.add(
+    ['v4.4.9', '1a1a512b983108015ced1e7a7c7775cfeec42d8c', 'v2.8.1','d11e0db', '7fd9215', '514a87f'] as RunConfiguration)
+
+def runConfigs = [] as Set
+
+// For each top of branch kernel tags that were not seen before, schedule one
+// job for each lttng/linux tracked configurations
+linuxLastTagIds.each { linuxTag ->
+  if (!oldLinuxTags.contains(linuxTag.value)) {
+    lttngBranchesOfInterest.each { lttngBranch ->
+      if (configurationOfInterest.contains([lttngBranch, linuxTag.key])) {
+        runConfigs.add([linuxTag.key, linuxTag.value,
+                    lttngBranch, toolsHeadCommits[lttngBranch],
+                    modulesHeadCommits[lttngBranch], ustHeadCommits[lttngBranch]]
+                    as RunConfiguration)
+
+        newOldLinuxTags.add(linuxTag.value)
+      }
+    }
+  }
+}
+
+// For each top of branch commits that were not seen before, schedule one job
+// for each lttng/linux tracked configurations
+toolsHeadCommits.each { toolsHead ->
+  if (!oldToolsHeadCommits.contains(toolsHead.value)) {
+    linuxLastTagIds.each { linuxTag ->
+      def lttngBranch = toolsHead.key
+      if (configurationOfInterest.contains([lttngBranch, linuxTag.key])) {
+        runConfigs.add([linuxTag.key, linuxTag.value,
+                    lttngBranch, toolsHeadCommits[lttngBranch],
+                    modulesHeadCommits[lttngBranch], ustHeadCommits[lttngBranch]]
+                    as RunConfiguration)
+
+        newOldToolsHeadCommits.add(toolsHead.value)
+      }
+    }
+  }
+}
+
+// For each top of branch commits that were not seen before, schedule one job
+// for each lttng/linux tracked configurations
+modulesHeadCommits.each { modulesHead ->
+  if (!oldModulesHeadCommits.contains(modulesHead.value)) {
+    linuxLastTagIds.each { linuxTag ->
+      def lttngBranch = modulesHead.key
+      if (configurationOfInterest.contains([lttngBranch, linuxTag.key])) {
+        runConfigs.add([linuxTag.key, linuxTag.value,
+                    lttngBranch, toolsHeadCommits[lttngBranch],
+                    modulesHeadCommits[lttngBranch], ustHeadCommits[lttngBranch]]
+                    as RunConfiguration)
+
+        newOldModulesHeadCommits.add(modulesHead.value)
+      }
+    }
+  }
+}
+
+// For each top of branch commits that were not seen before, schedule one job
+// for each lttng/linux tracked configurations
+ustHeadCommits.each { ustHead ->
+  if (!oldUstHeadCommits.contains(ustHead.value)) {
+    linuxLastTagIds.each { linuxTag ->
+      def lttngBranch = ustHead.key
+      if (configurationOfInterest.contains([lttngBranch, linuxTag.key])) {
+        runConfigs.add([linuxTag.key, linuxTag.value,
+                    lttngBranch, toolsHeadCommits[lttngBranch],
+                    modulesHeadCommits[lttngBranch], ustHeadCommits[lttngBranch]]
+                    as RunConfiguration)
+
+        newOldUstHeadCommits.add(ustHead.value)
+      }
+    }
+  }
+}
+
+// Save the tag and commit IDs scheduled in the past and during this run to the workspace
+saveCurrentIdsToWorkspace(newOldLinuxTags, linuxOnDiskPath)
+saveCurrentIdsToWorkspace(newOldToolsHeadCommits, toolsOnDiskPath)
+saveCurrentIdsToWorkspace(newOldModulesHeadCommits, modulesOnDiskPath)
+saveCurrentIdsToWorkspace(newOldUstHeadCommits, ustOnDiskPath)
+
+// Launch jobs
+println("Schedule canary jobs once a day")
+canaryRunConfigs.each { config ->
+  jobTypes.each { type ->
+    LaunchJob(type + '_canary', config)
+  }
+}
+
+if (runConfigs.size() > 0) {
+  println("Schedule jobs because of code changes.")
+  runConfigs.each { config ->
+    jobTypes.each { type ->
+      LaunchJob(CraftJobName(type, config), config);
+    }
+
+    // Jobs to run only on master branchs of both linux and lttng
+    if (config.linuxBranch.contains('master') &&
+        config.lttngBranch.contains('master')) {
+      LaunchJob(CraftJobName('vm_tests_fuzzing', config), config)
+    }
+  }
+} else {
+  println("No new commit or tags, nothing more to do.")
+}
index 9f7641bd21c0dcf6def37f13850c35860ca9f2d7..733b6ede771987de49913f97ab13380a3c6a1efd 100644 (file)
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 touch properties.txt
-if [ -n "${UST_BRANCH+x}" ]; then
-  LTTNG_UST_PATH="$WORKSPACE/src/lttng-ust"
-  git clone https://github.com/lttng/lttng-ust "$LTTNG_UST_PATH"
 
-  pushd "$LTTNG_UST_PATH"
-  git checkout "$UST_BRANCH"
-  popd
-
-  LTTNG_UST_COMMIT_ID="$(git --git-dir="$LTTNG_UST_PATH"/.git/ --work-tree="$LTTNG_UST_PATH" rev-parse --short HEAD)"
-  echo "LTTNG_UST_PATH=$LTTNG_UST_PATH" >> properties.txt
-  echo "LTTNG_UST_COMMIT_ID=$LTTNG_UST_COMMIT_ID" >> properties.txt
-fi
+KERNEL_COMMIT_ID=$kernel_tag_id
+LTTNG_MODULES_COMMIT_ID=$modules_commit_id
+LTTNG_TOOLS_COMMIT_ID=$tools_commit_id
+LTTNG_UST_COMMIT_ID=$ust_commit_id
 
 LTTNG_CI_PATH="$WORKSPACE/src/lttng-ci"
-LINUX_PATH="$WORKSPACE/src/linux"
-LTTNG_MODULES_PATH="$WORKSPACE/src/lttng-modules"
-LTTNG_TOOLS_PATH="$WORKSPACE/src/lttng-tools"
-
 echo "LTTNG_CI_PATH=$LTTNG_CI_PATH" >> properties.txt
-echo "LINUX_PATH=$LINUX_PATH" >> properties.txt
-echo "LTTNG_MODULES_PATH=$LTTNG_MODULES_PATH" >> properties.txt
-echo "LTTNG_TOOLS_PATH=$LTTNG_TOOLS_PATH" >> properties.txt
-
-# Checkout the last kernel tag for cases where the job is triggered by commits
-# on the LTTng repos
-KERNEL_TAG="$(git --git-dir="$LINUX_PATH"/.git/ --work-tree="$LINUX_PATH" describe --abbrev=0)"
-git --git-dir="$LINUX_PATH"/.git/ --work-tree="$LINUX_PATH" checkout "$KERNEL_TAG"
-
-KERNEL_COMMIT_ID="$(git --git-dir="$LINUX_PATH"/.git/ --work-tree="$LINUX_PATH" rev-parse HEAD)"
-LTTNG_MODULES_COMMIT_ID="$(git --git-dir="$LTTNG_MODULES_PATH"/.git/ --work-tree="$LTTNG_MODULES_PATH" rev-parse --short HEAD)"
-LTTNG_TOOLS_COMMIT_ID="$(git --git-dir="$LTTNG_TOOLS_PATH"/.git/ --work-tree="$LTTNG_TOOLS_PATH" rev-parse --short HEAD)"
-
-KERNEL_VERSION="$(make -s --directory=$LINUX_PATH kernelversion | sed 's/\./_/g; s/-/_/g';)"
 
 echo "KERNEL_COMMIT_ID=$KERNEL_COMMIT_ID" >> properties.txt
 echo "LTTNG_MODULES_COMMIT_ID=$LTTNG_MODULES_COMMIT_ID" >> properties.txt
 echo "LTTNG_TOOLS_COMMIT_ID=$LTTNG_TOOLS_COMMIT_ID" >> properties.txt
+echo "LTTNG_UST_COMMIT_ID=$LTTNG_UST_COMMIT_ID" >> properties.txt
 
 BASE_STORAGE_FOLDER="/storage/jenkins-lava/baremetal-tests"
 
@@ -60,10 +36,8 @@ echo "STORAGE_HOST=storage.internal.efficios.com" >> properties.txt
 echo "STORAGE_USER=jenkins-lava" >> properties.txt
 
 echo "BUILD_DEVICE=$BUILD_DEVICE" >> properties.txt
-KGITREPO=$(git --git-dir="$LINUX_PATH"/.git/ remote get-url origin)
-echo "KGITREPO=$KGITREPO" >> properties.txt
+echo "KGITREPO=$kernel_repo" >> properties.txt
 echo "STORAGE_KERNEL_FOLDER=$BASE_STORAGE_FOLDER/kernel" >> properties.txt
-echo "STORAGE_KERNEL_IMAGE=$BASE_STORAGE_FOLDER/kernel/$KERNEL_VERSION-$KERNEL_COMMIT_ID.$BUILD_DEVICE.bzImage" >> properties.txt
-echo "STORAGE_LINUX_MODULES=$BASE_STORAGE_FOLDER/modules/linux/$KERNEL_VERSION-$KERNEL_COMMIT_ID.$BUILD_DEVICE.linux.modules.tar.gz" >> properties.txt
-echo "STORAGE_LTTNG_MODULES=$BASE_STORAGE_FOLDER/modules/lttng/$KERNEL_VERSION-$KERNEL_COMMIT_ID-$LTTNG_MODULES_COMMIT_ID.$BUILD_DEVICE.lttng.modules.tar.gz" >> properties.txt
-
+echo "STORAGE_KERNEL_IMAGE=$BASE_STORAGE_FOLDER/kernel/$KERNEL_COMMIT_ID.$BUILD_DEVICE.bzImage" >> properties.txt
+echo "STORAGE_LINUX_MODULES=$BASE_STORAGE_FOLDER/modules/linux/$KERNEL_COMMIT_ID.$BUILD_DEVICE.linux.modules.tar.gz" >> properties.txt
+echo "STORAGE_LTTNG_MODULES=$BASE_STORAGE_FOLDER/modules/lttng/i$KERNEL_COMMIT_ID-$LTTNG_MODULES_COMMIT_ID.$BUILD_DEVICE.lttng.modules.tar.gz" >> properties.txt
This page took 0.035161 seconds and 4 git commands to generate.