From cdd4702353c145d18e48be7319cc75dfe082b6e9 Mon Sep 17 00:00:00 2001
From: Tim Jaacks <tim.jaacks@seco.com>
Date: Fri, 8 Sep 2023 07:40:59 +0200
Subject: [PATCH] Introduce separate variables to set RELEASE_NAME and
 RELEASE_VERSION

The expressions to calculate RELEASE_NAME and RELEASE_VERSION cannot be
stored within these variables themseselves. If set on the trigger level,
they would override the calculated values in build-version.env then,
as trigger variables always have the highest precedence.

Use separate variables RELEASE_VERSION_EXPRESSION and
RELEASE_NAME_EXPRESSION to define how RELEASE_VERSION and RELEASE_NAME
are calculated instead.
---
 build-pipeline.yml          | 18 +++++++++---------
 manifest-pipeline-yocto.yml |  6 +++---
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/build-pipeline.yml b/build-pipeline.yml
index 30a5e93c..4b17f40a 100644
--- a/build-pipeline.yml
+++ b/build-pipeline.yml
@@ -152,19 +152,19 @@ workflow:
     - when: always
   variables:
     BITBAKE_ENV_COMMAND: bitbake ${YOCTO_IMAGE} -e
-    # RELEASE_VERSION and RELEASE_NAME are eval'ed before saving them to version.env,
-    # so we can use deferred variable expansion or even command execution to construct
-    # their values.
-    RELEASE_VERSION: $${DISTRO_VERSION}
-    RELEASE_NAME: Yocto-${RELEASE_VERSION}
+    # RELEASE_VERSION_EXPRESSION and RELEASE_NAME_EXPRESSION are eval'ed and then saved
+    # as RELEASE_VERSION and RELEASE_NAME to version.env, so we can use deferred
+    # variable expansion or even command execution to construct their values.
+    RELEASE_VERSION_EXPRESSION: $${DISTRO_VERSION}
+    RELEASE_NAME_EXPRESSION: Yocto-$${RELEASE_VERSION}
   script:
     # Extract all variable assignments from the BitBake environment and source them.
     # The rather complicated regex also regards values containing escaped quotes.
     - source <( ${BITBAKE_ENV_COMMAND} | egrep '^[A-Z]\w*="([^\\"]+|\\.)*"$' )
-    - echo ${RELEASE_VERSION}
-    - echo ${RELEASE_NAME}
-    - RELEASE_VERSION=$(eval echo "${RELEASE_VERSION}")
-    - RELEASE_NAME=$(eval echo "${RELEASE_NAME}")
+    - echo ${RELEASE_VERSION_EXPRESSION}
+    - echo ${RELEASE_NAME_EXPRESSION}
+    - RELEASE_VERSION=$(eval echo "${RELEASE_VERSION_EXPRESSION}")
+    - RELEASE_NAME=$(eval echo "${RELEASE_NAME_EXPRESSION}")
     - echo "RELEASE_VERSION=${RELEASE_VERSION}" >> ${CI_PROJECT_DIR}/version.env
     - echo "RELEASE_NAME=${RELEASE_NAME}" >> ${CI_PROJECT_DIR}/version.env
     - cat ${CI_PROJECT_DIR}/version.env
diff --git a/manifest-pipeline-yocto.yml b/manifest-pipeline-yocto.yml
index 4844d4cf..560c742a 100644
--- a/manifest-pipeline-yocto.yml
+++ b/manifest-pipeline-yocto.yml
@@ -101,10 +101,10 @@ fngsystem-pipeline:
     # Escaped variables are not correctly passed to child pipelines. Proposed workaround
     # is to use raw variables, but we need at least GitLab 15.6 for that. As soon as we
     # update our GitLab, we can get rid of the DEFERRED_RELEASE_VERSION variable and
-    # assign its value to RELEASE_VERSION directly.
+    # assign its value to RELEASE_VERSION_EXPRESSION directly.
     DEFERRED_RELEASE_VERSION: $$(echo $$DISTRO_VERSION | sed "s/fngsystem-//")
-    RELEASE_VERSION: $DEFERRED_RELEASE_VERSION
-    RELEASE_NAME: FNGSystem-${DEFERRED_RELEASE_VERSION}
+    RELEASE_VERSION_EXPRESSION: $DEFERRED_RELEASE_VERSION
+    RELEASE_NAME_EXPRESSION: FNGSystem-${DEFERRED_RELEASE_VERSION}
     ARTIFACTS_PATH: build-*/tmp/deploy/images/**/*
     PACKAGE_TYPE: image
     ALPHAPLAN_STAGE: "true"
-- 
GitLab