From 6e372f62e053bc05d173cfc5663445f568ce2fc1 Mon Sep 17 00:00:00 2001
From: Martyn Welch <martyn.welch@collabora.com>
Date: Tue, 5 Mar 2019 09:31:23 +0000
Subject: [PATCH] Include SABRE Lite U-Boot installer script in the Jenkinsfile

Signed-off-by: Martyn Welch <martyn.welch@collabora.com>
---
 Jenkinsfile | 58 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 53 insertions(+), 5 deletions(-)

diff --git a/Jenkinsfile b/Jenkinsfile
index 8b4ec3f6..b574f328 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -29,6 +29,8 @@ test_lava_credentials = 'apertis-lava-user'
 
 demopack = "https://images.apertis.org/media/multimedia-demo.tar.gz"
 
+installer_repo_url = "https://repositories.apertis.org/apertis/"
+
 sysroot_url_prefix = image_url_prefix + "/sysroot/"
 
 def architectures = [
@@ -36,6 +38,7 @@ def architectures = [
         boards: ['uefi'],
         types: [
             minimal: [
+                ospack: true,
                 image: true,
                 sysroot: false,
                 ostree: true,
@@ -43,12 +46,14 @@ def architectures = [
             ],
             target: [
                 args: "-t demopack:${demopack}",
+                ospack: true,
                 image: true,
                 sysroot: false,
                 //ostree: true,
             ],/*
             sysroot: [
                 args: '--scratchsize 10G',
+                ospack: true,
                 image: false,
                 sysroot: true,
                 ostree: false,
@@ -56,6 +61,7 @@ def architectures = [
             sdk: [
                 args: "-t demopack:${demopack} -t sampleappscheckout:enabled --scratchsize 10G",
                 boards: [ 'sdk' ],
+                ospack: true,
                 image: true,
                 sysroot: false,
                 ostree: false,
@@ -66,6 +72,7 @@ def architectures = [
             basesdk: [
                 args: '--scratchsize 10G',
                 boards: [ 'sdk' ],
+                ospack: true,
                 image: true,
                 sysroot: false,
                 ostree: false,
@@ -80,18 +87,21 @@ def architectures = [
         boards: ['uboot'],
         types: [
             minimal: [
+                ospack: true,
                 image: true,
                 sysroot: false,
                 ostree: true,
             ],
             target: [
                 args: "-t demopack:${demopack}",
+                ospack: true,
                 image: true,
                 sysroot: false,
                 //ostree: true,
             ],/*
             sysroot: [
                 args: '--scratchsize 10G',
+                ospack: true,
                 image: false,
                 sysroot: true,
                 ostree: false,
@@ -102,22 +112,28 @@ def architectures = [
         boards: ['uboot'],
         types: [
             minimal: [
+                ospack: true,
                 image: true,
                 sysroot: false,
                 ostree: true
             ],/*
             sysroot: [
                 args: '--scratchsize 10G',
+                ospack: true,
                 image: false,
                 sysroot: true,
                 ostree: false
             ],
             devroot: [
                 args: '--scratchsize 10G',
+                ospack: true,
                 image: false,
                 sysroot: false,
                 ostree: false
             ]*/
+            installer: [
+                installers: [ 'mx6qsabrelite' ]
+            ]
         ]
     ]
 ]
@@ -380,6 +396,25 @@ def buildSysroot(architecture, type, debosarguments = "") {
     }
 }
 
+def buildInstaller(architecture, type, target, debosarguments = "") {
+    def image_name = "u-boot-installer-${target}"
+
+    stage("${architecture} ${target} installer image") {
+      sh(script: """
+          mkdir -p ${PIPELINE_VERSION}/${architecture}/${type}/${target}
+          cd ${PIPELINE_VERSION}/${architecture}/${type}/${target}
+          debos ${debosarguments} \
+            --show-boot \
+            -t architecture:${architecture} \
+            -t target:${target} \
+            -t mirror:${installer_repo_url} \
+            -t suite:${release} \
+            -t timestamp:${PIPELINE_VERSION} \
+            -t image:${image_name} \
+            ${WORKSPACE}/uboot-installer.yaml""")
+    }
+}
+
 
 /**
  * Build OSPack for architecture and start a parallel build of artifacts related
@@ -387,7 +422,7 @@ def buildSysroot(architecture, type, debosarguments = "") {
  *
  * @boards -- array with board names
  */
-def buildImages(architecture, type, boards, debosarguments = "", image = true, sysroot = false, ostree = false, lxc = false, production = false) {
+def buildImages(architecture, type, boards, debosarguments = "", ospack = true, image = true, sysroot = false, installers = [], ostree = false, lxc = false, production = false) {
   return {
     node("docker-slave") {
       checkout scm
@@ -412,8 +447,10 @@ def buildImages(architecture, type, boards, debosarguments = "", image = true, s
 
               // The real work starts here
               try {
-                // If that fails -- do not need to build the rest
-                buildOSpack(architecture, type, debosarguments) 
+                if (ospack) {
+                  // If that fails -- do not need to build the rest
+                  buildOSpack(architecture, type, debosarguments)
+                }
 
                 if (image) {
                   // Create apt-based images for all boards
@@ -464,6 +501,17 @@ def buildImages(architecture, type, boards, debosarguments = "", image = true, s
                   }
                 }
 
+                // Create installer
+                for(String installer: installers) {
+                  try {
+                    buildInstaller(architecture, type, installer, debosarguments)
+                    buildStatus["installer"] = true
+                  } catch (e) {
+                    // If image build failed -- do not fail other types but do not need to start tests for it
+                    buildStatus["installer"] = false
+                  }
+                }
+
                 // Mark the whole pipeline as failed in case of failure at any stage
                 if (buildStatus.containsValue(false)) {
                   currentBuild.result = 'FAILURE'
@@ -534,12 +582,12 @@ buildCandidates.each { name, arch ->
         if (!params.requires) {
             /* first, build all jobs which don’t have any dependencies, in parallel */
             first_pass << [("$name $type"):
-                buildImages(name, type, merged.boards, merged.args, merged.image, merged.sysroot, merged.ostree, merged.lxc, production)
+                buildImages(name, type, merged.boards, merged.args, merged.ospack, merged.image, merged.sysroot, merged.installers, merged.ostree, merged.lxc, production)
             ]
         } else {
             /* second, build any jobs which depend on jobs from the first pass, also in parallel */
             second_pass << [("$name $type"):
-                buildImages(name, type, merged.boards, merged.args, merged.image, merged.sysroot, merged.ostree, merged.lxc, production)
+                buildImages(name, type, merged.boards, merged.args, merged.ospack, merged.image, merged.sysroot, merged.installers, merged.ostree, merged.lxc, production)
             ]
         }
     }
-- 
GitLab