From 6d4446d1a9515df503699b8f080e52673a46236e Mon Sep 17 00:00:00 2001
From: Maarten de Waard <maarten@greenhost.nl>
Date: Thu, 28 Oct 2021 16:17:48 +0200
Subject: [PATCH] move when: to rules:

TRIGGER_JOBS=ci-test-image-build
---
 .gitlab-ci.yml | 40 +++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 93dbbfc16..d223947ff 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -59,19 +59,6 @@ include:
     - if: '$CI_COMMIT_MESSAGE =~ /TRIGGER_JOBS=.*enable-/'
     - if: '$CI_COMMIT_BRANCH == "master"'
 
-.ci_test_image_build_rules:
-  rules:
-    # Automatically rebuild the container image if this file, the Dockerfile,
-    # the installed requirements or the kaniko template change
-    - changes:
-        - Dockerfile
-        - requirements.txt
-        - .gitlab/ci_templates/kaniko.yml
-    # Also rebuild when the CI variable contain this jobs name
-    # or commit msg contains /TRIGGER_JOBS=.*ci-test-image-build/
-    - if: '$TRIGGER_JOBS =~ /ci-test-image-build/'
-    - if: '$CI_COMMIT_MESSAGE =~ /TRIGGER_JOBS=.*ci-test-image-build/'
-
 # app rules
 #
 # Define the rules when/if app specific jobs are run.
@@ -241,9 +228,19 @@ ci-test-image-build:
     url: https://open.greenhost.net:4567/openappstack/openappstack/openappstack-ci:${CI_COMMIT_REF_SLUG}
     on_stop: delete-image
     auto_stop_in: 3 weeks
+  rules:
+    # Automatically rebuild the container image if this file, the Dockerfile,
+    # the installed requirements or the kaniko template change
+    - changes:
+        - Dockerfile
+        - requirements.txt
+        - .gitlab/ci_templates/kaniko.yml
+    # Also rebuild when the CI variable contain this jobs name
+    # or commit msg contains /TRIGGER_JOBS=.*ci-test-image-build/
+    - if: '$TRIGGER_JOBS =~ /ci-test-image-build/'
+    - if: '$CI_COMMIT_MESSAGE =~ /TRIGGER_JOBS=.*ci-test-image-build/'
   extends:
     - .kaniko_build
-    - .ci_test_image_build_rules
   interruptible: true
 
 report-ci-image-tag:
@@ -722,7 +719,6 @@ terminate-droplet:
 # image re-build as well
 delete-image:
   stage: build
-  when: manual
   needs:
     - job: ci-test-image-build
   variables:
@@ -733,5 +729,15 @@ delete-image:
   environment:
     name: image/$CI_COMMIT_REF_SLUG
     action: stop
-  extends:
-    - .ci_test_image_build_rules
+  rules:
+    # Copy the rules from ci-test-image-build to prevent broken pipelines when
+    # that job did not run
+    - changes:
+        - Dockerfile
+        - requirements.txt
+        - .gitlab/ci_templates/kaniko.yml
+      when: manual
+    - if: '$TRIGGER_JOBS =~ /ci-test-image-build/'
+      when: manual
+    - if: '$CI_COMMIT_MESSAGE =~ /TRIGGER_JOBS=.*ci-test-image-build/'
+      when: manual
-- 
GitLab