Gitlab CI can trigger other project pipeline stage?

Viewed 401

I have an A project and an E2E project. I want to deploy A project trigger E2E pipeline run test but I just want the trigger test stage. we don't need trigger E2E to build deploy ...etc

e2e_tests:
    stage: test
    trigger:
        project: project/E2E
        branch: master
        strategy: depend
        stage: test

I have tried to use the stage in config. but got error unknown keys: stage

have any suggestions?

1 Answers

In your E2E project, the one that receives the trigger, you can tell a job to only run when the pipeline source is a trigger using the rules syntax:

build-from-trigger:
  stage: build
  when: never
  rules:
    - if: "$CI_COMMIT_REF_NAME == 'master' && $CI_PIPELINE_SOURCE == 'trigger'
      when: always
  script:
    - ./build.sh # this is just an example, you'd run whatever you normally would here

The first when statement, when: never sets the default for the job. By default, this job will never run. Then using the rule syntax, we set a condition that will allow the job to run. If the CI_COMMIT_REF_NAME variable (the branch or tag name) is master AND the CI_PIPELINE_SOURCE variable (whatever kicked off this pipeline) is a trigger, then we run this job.

You can read about the when keyword here: https://docs.gitlab.com/ee/ci/yaml/#when, and you can read the rules documentation here: https://docs.gitlab.com/ee/ci/yaml/#rules

Related