79668272

Date: 2025-06-16 21:51:21
Score: 3
Natty:
Report link

I hope I get you right and it will help you or other people who face the same issue.

I was trying to figure how to set matrix dinamically 'cause I have to check services' dirs that have been changed and save services' names, than run pipeline for each service. This is what I did:

I have the first job that defines what kind of services I have to rerun (define_changed_service) and the second job (trigger_test_services) which triggers this artifact:

define_changed_service:
  image: alpine:latest
  stage: build-push
  before_script:
    - apk add --no-cache git grep sed coreutils
    - which git grep sed sort
  script:
    - SERVICES=$(git diff --name-only origin/main...HEAD | grep -E '^([^/]+/){3}(src|\.docker)/' | sed -E 's@^([^/]+/[^/]+/[^/]+)/.*@\1@' | sort -u | sed 's@/@-@g' | paste -sd "," -)
    - echo "Services $SERVICES"
    - echo "test-services:" > matrix.yml
    - echo "  parallel:" >> matrix.yml
    - echo "    matrix:" >> matrix.yml
    - |
      echo "$SERVICES" | tr ',' '\n' | while read srv; do
        echo "      - SERVICE: $srv" >> matrix.yml
      done
    - echo "  script:" >> matrix.yml
    - echo "    - echo \"Running tests for service \$SERVICE\"" >> matrix.yml
    - cat matrix.yml
  artifacts:
    paths:
      - matrix.yml
  
trigger_test_services:
  stage: build-push
  needs:
    - job: define_changed_service
      artifacts: true
  trigger:
    include:
      - artifact: matrix.yml
        job: define_changed_service
    strategy: depend

AND IT WORKS! I can believe I actually DID IT. I run into my browser history and went here to post the answer. This is my first answer on stackoverflow, lol. Enjoy. Let me now if it will help. I added screenshots on the off-chance
My pipeline

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): face the same issue
  • Low reputation (1):
Posted by: Антон Фокин