'Is it possible to have gitlab CI trigger another pipeline?
I'm new to gitlab CI so I'm still trying to get my head around it but I'm wondering if it's possible to do the following?
Developers work in REPO A
QA work in REPO B
When the pipeline from REPO A kicks off is it possible to have it trigger the pipeline from REPO B with a command and pass variables?
That way Developers in REPO A can work on their part of the project e.g. login form but REPO B can contain the entire end to end suite of tests for all features, so if a new team is formed and work on REPO C they can also trigger tests in REPO B.
This would mean QA always work in one repo, and if another repo wants to do a deployment they can call their subset of tests but nightly REPO B can run the full end to end suite with different browsers, devices etc.
Solution 1:[1]
There is the concept of Multi-Project Pipelines which exactly allow your desired behaviour.
In your case this would be in Project A and C
externalTest:
variables:
ENVIRONMENT: aVariableValue
stage: deploy
trigger: my-namespace/repo-b
Solution 2:[2]
There is a way in the documents of Triggering pipelines through the API which gives us the ability of triggering another pipeline using GitLab API in the current running pipeline:
This way of triggering can only be used when invoked inside .gitlab-ci.yml, and it creates a dependent pipeline relation visible on the pipeline graph. For example:
build_docs: stage: deploy script: - curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.example.com/api/v4/projects/9/trigger/pipeline only: - tags
Pipelines triggered that way also expose a special variable:
CI_PIPELINE_SOURCE=pipeline
.
If you want to trigger REPO B pipeline from REPO A and REPO C, please remember that you must replace the REPO B project id in the above URL instead of example id.
Solution 3:[3]
@doctor-wh, please read this article from GitLab team, it helps me in the way I needed.
I had needed to start CI process of REPO A, when someone push their codes on REPO B which was related to REPO A, so it was amazingly helpful for me.
https://docs.gitlab.com/ee/ci/multi_project_pipelines.html
hope it will help you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | secustor |
Solution 2 | AmirMohammad Dadkhah |
Solution 3 | Amin Eshtiaghi |