continuous integration - GitLab CI job with inputs to configure a matrix trigger job - Stack Overflow

admin2025-04-16  1

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?

转载请注明原文地址:http://www.anycun.com/QandA/1744765054a87300.html