Search code examples
gitlabgitlab-cipipelinegitlab-ci-runnergitlab-api

How to run job-to-job linking in multi-project pipelines on GitLab CI


Example:

I have 3 different pipelines (projects) in GitLab. Each pipeline has multiple jobs, each targeting a different remote VM and set a different GitLab CI environment. The jobs are all manually triggered (currently). What I am trying to achieve is a linking (multi-project) pipeline that runs like this: Once I trigger job "X" in the pipeline #1, upon succeeding, that will trigger ONLY job "X" in the pipeline #2 which then again, upon success, will trigger ONLY job "X" in pipeline #3.

By job "X" I mean a job that runs on a certain remote VM, I don't want the entire pipeline to run since I don't want to change all targets. All examples I found only work at a pipeline level, not at the job level. What am I missing?

PS: I'm new to the GitLab CI scene so please forgive my lack of understanding in case there's an easy solution that I've missed.


Solution

  • It's possible yes. If I take your example, in job "X" from pipeline 1, you can trigger a pipeline from another project using Gitlab API :

    script:
      - "curl --request POST --form token=TOKEN --form ref=master https://gitlab.example.com/api/v4/projects/9/trigger/pipeline"
    

    To ensure triggering only job "X" from pipeline 2, add use only keyword with api condition :

    job_X:
      only:
        - api