Gitlab pipeline: use variable in trigger path

1.4k views Asked by At

I'm trying to develop a common gitlab pipeline that uses a matrix to trigger another pipeline but I want to add a variable in the path. What I wrote till now is:

variables:
  PROJECT_NAME: name
  PROJECT_HELM: helmpipe
  DEV_CUSTOMERS: cust1 cust2


deploy:dev:
  stage: deploy
  variables:
    UPSTREAM_CI_COMMIT_SHORT_SHA: $CI_COMMIT_SHORT_SHA
    UPSTREAM_CI_COMMIT_BRANCH: $CI_COMMIT_BRANCH
    UPSTREAM_CI_COMMIT_TAG: $CI_COMMIT_TAG
    IMAGE_NAME: ${PROJECT_NAME}
    CUSTOMER: $CUSTOMER
  trigger: my/project/$PROJECT_HELM
  parallel:
    matrix:
      - CUSTOMER: $DEV_CUSTOMERS
  only:
    - DEV

But gitlab returns error saying that the triggered project can not be found. It seems that the variable $PROJECT_HELM is not converted to its real value in trigger path. How can I do it?

Thanks

1

There are 1 answers

3
Sanjay Bharwani On

Below is the working example where the variable ENV is used to trigger the sit pipeline. My pipeline file is in pipeline folder at root level. And the file name is sit-pipeline.yaml

stages:          
  - build

variables:
  ENV: sit

sit-pipeline:
  stage: build
  trigger:
    include:
      - local: pipeline/${ENV}-pipeline.yaml

There could be 2 issues

  1. Either you need to use ${var} syntax instead of $var syntax trigger: my/project/${PROJECT_HELM}
  2. Or PROJECT_HELM variable should resolve to a yaml file defining the pipeline. Your variable is assigned to helmpipe so I think you are missing .yaml extension