I'm trying to write a GitLab CI/CD pipeline job that is part of a GitLab Component project. Specifically, this job is designed to trigger a multi-project pipeline, but I want the pipeline(s) to be triggered to be defined as an input by the user. And importantly, if the user has nothing to trigger, this job should have a rule that excludes it from the pipeline. The following is how I'm constructing this.
spec:
inputs:
trigger-projects:
type: array
default: []
---
trigger dependency validation:
stage: build
rules:
- if: $[[ inputs.trigger-projects ]] # GitLab takes umbrage here
changes: [my_file]
parallel:
matrix:
- PROJECT: $[[ inputs.trigger-projects ]] # GitLab also takes umbrage here
VARIABLE_TO_PASS_ON: "VALUE"
trigger:
project: ${PROJECT}
strategy: depend
The expectation for above is that if the user never defines trigger-projects
when this job is included, the rules
section will see an empty array and should evaluate to false, preventing this job from being included. Here's the first issue. I cannot determine a valid if statement to check if the input array is non-empty. If I circumvent this issue by creating a second boolean input (less desirable) to just include or disclude this job, then GitLab seems to dislike trying to assign an array to the PROJECT
variable in the matrix
section.
Is it possible to do what I'm trying to do?