7

I'm aware that is possible to trigger another pipeline from another project by adding the below commands in a gitlab-ci file:

bridge: stage: stage_name_here trigger: project: path_to_another_project branch: branch_name strategy: depend 

The problem is that the config above will trigger all jobs, and I want to trigger only 2 jobs within the pipeline.

Any idea on how to trigger only those 2 specific jobs?

3 Answers 3

3

Instead of defining a variable that needs to be passed by the upstream pipeline that is triggering the downstream pipeline, I simply added the lines below in the jobs that I don't want to run in the downstream pipeline when triggered by another job:

except: refs: - pipelines 

source: https://docs.gitlab.com/ee/ci/triggers/index.html#configure-cicd-jobs-to-run-in-triggered-pipelines

Sign up to request clarification or add additional context in comments.

1 Comment

Not suitable for a scenario where there are more triggerable jobs and various upstreams are able to run their own selection of jobs.
1

You can play with rules, only and except keywords in triggered ci file, for example add this to jobs that you want to trigger:

except: variables: - $CI_PROJECT_ID != {{ your main project id }} 

And for jobs you don't want trigger this:

except: variables: - $CI_PROJECT_ID == {{ your main project id }} 

Or if you want use rules, add this to jobs you want to run in main project:

rules: - if: $CI_PROJECT_ID == {{ your main project id }} when: never - when: always 

5 Comments

As far as I know, the $CI_PROJECT_ID gets the id of the current project, right? (https://docs.gitlab.com/ee/ci/variables/predefined_variables.html). The jobs that I want to trigger and that will have the logic above are in a different project from the project that are triggering those jobs, so the comparison $CI_PROJECT_ID == {{ your main project id }} will always be false, right?
You may just use custom variable flags, eg. IGNORE_JOB_A; define them in the other projects Job - and then drive the job selection based on that. Just in case if you are looking for something like reusable/common jobs; you may create templates and then include it in your project gitlab-ci file see: docs.gitlab.com/ee/ci/yaml/includes.html
I just need to pass the variable from the upstream job to the downstream job in the other project, right? Would this work in the upstream project? variables: CI_PROJECT_ID: $CI_PROJECT_ID And then I can use the logic suggest above by @Makariy , using the value of $CI_PROJECT_ID sent from the upstream project?
@jimmy your downstream pipe starts at the same project and same commit as upstream, so you do't need to pass predefined variables to it
I choose $CI_PROJECT_ID just for example, you can choose your conditions
0

To trigger a specific job in the downstream pipeline. What you can do is to pass an env variable into the trigger job:

variables: ENV: qa1 child2: trigger: include: .child-pipeline.yml forward: yaml_variables: true 

The above will pass the variable from the trigger job into the downstream job then on the specific downstream job you want to trigger add the following rules:

 rules: - if: $CI_PIPELINE_SOURCE == "pipeline" && $ENV == "qa1" when: always 

with that rule it will only tigger that job from the list of all jobs in the downstream pipeline.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.