Gitlab multiproject pipeline does not trigger the steps from the downstream yml correctly

I have a multiproject pipeline in this case project A and project B.

I want to use project A as a trigger for Project B, and Project B has it’s own pipeline steps for Cypress test automation. However what happens is that Project A gives an error saying that npm can’t be installed. If I run my Project B pipeline separately it works fine and of course, finds the NPM package etc.

This is the error I am getting.

How I understand the whole concept of multiproject pipeline was to have different project having their own tasks and steps but still be able to communicate with each other. However the problem that I am seeing is that it allows it to trigger Project B but tries to install it still in Project A some how.

I also tried it with a simple npm install and cypress run, but the problem is the same.


In this case test automation is the correct path and echo’ed from the Project B pipeline

Screenshot 2023-03-25 at 13.17.39
As you can see when I trigger from Project A the path has changed to “Verify” instead of “test automation” so the scope is wrong.

What am I doing wrong or what am I missing exactly?

Project A

trigger_cypress
  trigger:
    include:
      - project: 'gitlabname/projectname'
        file: '.gitlab-ci.yml'

Project B


stages:
  - build
  - test
  - report
  - notify

variables:
  npm_config_cache: "$CI_PROJECT_DIR/.npm"
  CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/Cypress"

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - .npm
    - cache/Cypress
    - node_modules

build_cypress:
  image: <image name>
  stage: build
  script:
    - npm ci
    - npx cypress cache path
    - npx cypress cache list

run_cypress_tests:
  image: <image name>
  stage: test
  parallel: 4
  script:
  - |
    if [  -f .cache_exists ]; then
      echo "cache already exists"
    else
      npm install
      echo > .cache_exists
    fi
  - npx cypress run --env split=true --reporter cypress-multi-reporters --reporter-options configFile=reporter-config.json reportDir="cypress/results",overwrite=false,html=false,json=true
  artifacts:
    when: always
    expire_in: 1 week
    paths:
      # the path here is needed to expose the file and be able to send it to Datadog.
      - $CI_PROJECT_DIR/cypress/results/**/*.xml
      # the path here is needed to send the data to Teams
      - $CI_PROJECT_DIR/cypress/results/*.json
      # the path here is needed to get the video artifacts
      - $CI_PROJECT_DIR/cypress/videos/*.mp4

merge_cypress_artifacts:
  image: <image name>
  stage: report
  variables:
    JOB_ID: $CI_JOB_ID
  dependencies:
    - run_cypress_tests
  needs:
    - job: run_cypress_tests
      artifacts: true
  script:
    - echo "JOB_ID=$JOB_ID" >> build.env #this is needed to use later on in notify stage
    - npm run merge-reports
    - npx mochawesome-merge "cypress/results/*.json" > mochawesome.json
  artifacts:
    when: always
    expire_in: 1 week
    paths:
      # the path here is needed to expose the file and be able to send it to Datadog.
      - $CI_PROJECT_DIR/cypress/results/combined.xml
      # the path here is needed to send the data to Teams
      - $CI_PROJECT_DIR/mochawesome.json
      - $CI_PROJECT_DIR/cypress/videos/*.mp4
    reports:
      dotenv: build.env

send_results_datadog:
  image: <image name>
  stage: report
  dependencies:
    - merge_cypress_artifacts
  needs:
    - job: merge_cypress_artifacts
      artifacts: true
  script:
    - npm install -g @datadog/datadog-ci
    - DD_ENV=CI DATADOG_API_KEY=$DATADOG_API_KEY DATADOG_SITE=datadoghq.com datadog-ci junit upload --service system cypress/results/combined.xml

notify_teams:
  image: <image name>
  stage: notify
  dependencies:
    - merge_cypress_artifacts
  needs:
    - job: merge_cypress_artifacts
      artifacts: true
  script:
    - npm install test-results-reporter
    - npm install -g dotenv-cli
    - mkdir test-results
    - cp $CI_PROJECT_DIR/mochawesome.json test-results
    - |
      dotenv -v WEBHOOK=${CYPRESS_WEBHOOK} -v TEAMS_URL=<SOME URL> npx test-results-reporter publish -c config.json

Thanks in advance.
Rody

Your code shows parent-child pipeline which indeed runs in the same project. A multiproject pipeline would look like this:

trigger_job:
  trigger:
    project: project-group/my-downstream-project

See Trigger a Multiproject downstream pipeline.

I hope that helps.