From f892500f71f6fb29d9cd0442a2824b045b095ebe Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@seco.com>
Date: Tue, 25 Jul 2023 14:58:04 +0200
Subject: [PATCH] Yocto build: make main artifacts path configurable

Instead of specifying all possible artifacts paths and abusing the fact
that GitLab ignores non-existing paths during artifact upload, implement
a cleaner solution with a configurable path.
---
 build-common.yml              | 9 +++------
 build-jobs-ci-test.yml.jinja2 | 4 ++++
 build-jobs-yocto.yml.jinja2   | 3 +++
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/build-common.yml b/build-common.yml
index e0a0948b..628bc034 100644
--- a/build-common.yml
+++ b/build-common.yml
@@ -99,13 +99,10 @@ workflow:
     reports:
       dotenv: build.env
     paths: &artifacts_paths
-      # List of all potential artifact paths. Not all of them are present in each build
-      # configuration, e.g. the SDK path exists in SDK builds only. We still specify all
-      # of them here in order to have a generic build class for all builds. Pathsspecs
-      # which do not exist in a specific configuration are simply ignored by GitLab.
-      - build-*/tmp/deploy/images/**/*
+      - ${ARTIFACTS_PATH}
+      # The license manifest is not available on all builds (e.g. SDK builds), but if it
+      # exists, we're adding it to the artifacts.
       - build-*/tmp/deploy/licenses/**/license.manifest
-      - build-*/tmp/deploy/sdk/*
       - build.env
   cache:
     # Cache the build artifacts for subsequent stages in the same pipeline
diff --git a/build-jobs-ci-test.yml.jinja2 b/build-jobs-ci-test.yml.jinja2
index ce9603f7..f5a5ce5a 100644
--- a/build-jobs-ci-test.yml.jinja2
+++ b/build-jobs-ci-test.yml.jinja2
@@ -95,6 +95,8 @@ build:check-foo-branch:
       echo "ERROR: Branches do not match!"
       exit 1
     fi
+  artifacts: null
+  cache: null
 
 .simulate_build:
   extends:
@@ -120,6 +122,7 @@ simulate-build-seco-mx6:
     # branch, because we don't always execute the full pipeline on the master branches.
     # In those cases the actual build job does not exist, which results in a 404 error.
     BUILD_ARTIFACTS: https://git.seco.com/seco-ne/yocto/manifest/-/jobs/artifacts/kirkstone/3.0/download?job=build-seco-mx6
+    ARTIFACTS_PATH: build-*/tmp/deploy/images/**/*
   cache:
     - !reference [.buildbase, cache]
     # Additionally cache the build artifacts for re-runs of this job in other pipelines
@@ -135,6 +138,7 @@ simulate-buildsdk-seco-mx6:
       allow_failure: true
   variables:
     BUILD_ARTIFACTS: https://git.seco.com/seco-ne/yocto/manifest/-/jobs/artifacts/kirkstone/3.0/download?job=buildsdk-seco-mx6
+    ARTIFACTS_PATH: build-*/tmp/deploy/sdk/*
   cache:
     - !reference [.buildbase, cache]
     # Additionally cache the build artifacts for re-runs of this job in other pipelines
diff --git a/build-jobs-yocto.yml.jinja2 b/build-jobs-yocto.yml.jinja2
index c6390137..da4172cd 100644
--- a/build-jobs-yocto.yml.jinja2
+++ b/build-jobs-yocto.yml.jinja2
@@ -57,6 +57,7 @@ build-{{ machine }}:
     CI_PARAM_DISTRO: {{ CI_PARAM_DISTRO }}
     CI_PARAM_IMAGE: {{ CI_PARAM_IMAGE }}
     INSTALLSCRIPT: "fng-install.sh"
+    ARTIFACTS_PATH: build-*/tmp/deploy/images/**/*
 
 # Build jobs for the sdk
 buildsdk-{{ machine }}:
@@ -65,6 +66,7 @@ buildsdk-{{ machine }}:
     CI_PARAM_MACHINE: {{ machine }}
     CI_PARAM_DISTRO: {{ CI_PARAM_DISTRO }}
     CI_PARAM_IMAGE: {{ CI_PARAM_IMAGE }}
+    ARTIFACTS_PATH: build-*/tmp/deploy/sdk/*
 {% endif %}
 
 {% if CI_PARAM_IMAGE_FNG %}
@@ -76,6 +78,7 @@ build-{{ machine }}-fngsystem:
     CI_PARAM_DISTRO: {{ CI_PARAM_DISTRO_FNG }}
     CI_PARAM_IMAGE: {{ CI_PARAM_IMAGE_FNG }}
     INSTALLSCRIPT: "fngsystem-self-update.sh"
+    ARTIFACTS_PATH: build-*/tmp/deploy/images/**/*
 {% endif %}
 
 
-- 
GitLab