Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 556
Doctor Who Avatar asked Jun 11 '20 13:06

Doctor Who


People also ask

Can you have multiple pipelines in GitLab?

Yes, you can use the rules syntax. You can use this in combination with regex for commit message, ci_pipeline_source or any other available CI variables. In doing this you can compose the jobs/pipelines you want in its own yml file and then define the jobs using those templates in the gitlab-ci.

Can you have multiple GitLab CI files?

No, you can't have multiple gitlab-ci files per repository.

Do GitLab stages run in parallel?

GitLab provides a method to make clones of a job and run them in parallel for faster execution using the parallel: keyword.


2 Answers

There is the concept of Multi-Project Pipelines which exactly allow your desired behaviour.

See https://docs.gitlab.com/ee/ci/multi_project_pipelines.html#creating-multi-project-pipelines-from-gitlab-ciyml

In your case this would be in Project A and C

externalTest: 
    variables: 
        ENVIRONMENT: aVariableValue
    stage: deploy 
    trigger: my-namespace/repo-b
like image 136
secustor Avatar answered Oct 12 '22 11:10

secustor


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.

like image 40
AmirMohammad Dadkhah Avatar answered Oct 12 '22 09:10

AmirMohammad Dadkhah