Skip jobs on variable regex that use another variable as part of regex
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
At my work we have a project consisting out of many products that shares common parts. CI pipeline runs 100+ jobs and this takes a really long time specifically on dev branch that have changes for only one product.
Lets imagine example:
stages:
- build
.template: &build_product
stage: build
script:
- JOB_NAME=( $CI_JOB_NAME )
- export PRODUCT=${JOB_NAME[1]}
- case $CI_COMMIT_TAG in "") RELEASE=0;; *) RELEASE=1;; esac
- echo $RELEASE
except:
variables:
# CI config incorrect
- $CI_COMMIT_TITLE =~ /.[PROD${CI_JOB_NAME[1]}\]/i
# Dependent on script part, but correct config
- $CI_COMMIT_TITLE =~ /.[PROD${JOB_NAME[1]}\]/i
build 12345: *build_product
build 12346: *build_product
Anchors are used to create common CI stage template for all products inside project.
I am trying to achieve functionality to push a commit with "[PROD12345]" inside commit title (firs line) to skip all jobs not related to specified product. (build 12346 and others need to be skipped then)
I have 3 problems\questions:
-
How to pass a CI variable into regex
$CI_COMMIT_TITLE =~ /.[PROD${CI_JOB_NAME[1]}\]/iI suggest${CI_JOB_NAME[1]}to evaluate to12345and CI checks$CI_COMMIT_TITLE =~ /.[PROD12345\]/iin commit title. How to do it right? -
If code mentioned in question 1 is not possible to make work I tried to explicitly for each product's job:
build 12345: *build_product
except:
variables:
- $CI_COMMIT_TITLE =~ /.[PROD12345\]/i
# the same for other jobs
- Why CI allows to use variable created in
scriptifexceptis evaluated before any docker images?