Run specific child pipeline

I have simple pipeline that just triggers children pipelines based on changes. I would like to run specific child using gitlab.com page or through the API. For now I handle that with running parent pipeline for specific branch and manually stop all children pipelines but one

Thanks for help!

Any hints?

Hi @kosciej

Can you post a rough outline of your .gitlab-ci.yml files?

Thanks for reply @snim2, here it is:

# .gitlab-ci.yml

stages:
  - triggers

trigger_a:
  stage: triggers
  trigger:
    include: a/.gitlab-ci.yml
    strategy: depend
  rules:
    - changes:
        - a/**/*

trigger_b:
  stage: triggers
  trigger:
    include: b/.gitlab-ci.yml
    strategy: depend
  rules:
    - changes:
        - b/**/*

# trigger_c, trigger_d ...

And now I would like run only pipeline from a/gitlab-ci.yml

Right, so should it run trigger_a and trigger_b most of the time, but run trigger_a only when you start the pipeline via the API or have I misunderstood?

That pipeline works fine, now I seek for any legit way of running single trigger on specific branch.
Via the API, via the dashboard, via the hack, anything that is simpler than running full pipeline with run pipeline button in gitlab instance and manually disable all but one.

It’s still not quite clear to me what you want; but I think you just need to tweak the rules sections of your YAML config. Let’s imagine you don’t want trigger_b to run on the develop branch, you would add something like:

stages:
  - triggers

trigger_a:
  stage: triggers
  trigger:
    include: a/.gitlab-ci.yml
    strategy: depend
  rules:
    - changes:
        - a/**/*

trigger_b:
  stage: triggers
  trigger:
    include: b/.gitlab-ci.yml
    strategy: depend
  rules:
    - if '$CI_COMMIT_BRANCH == "develop"'
      when: never
    - changes:
        - b/**/*

Does that help at all?

Unfortunately it doesn’t as it’s not that case. Let me describe scenario, so maybe things become more clear:

  1. I make a commit that touch only a directory. Main pipeline runs, triggers only a/.gitlab-ci.yml. Everything is as expected. This commit is important for me so I tag it with XYZ
  2. I do more commits that touches different things, every commit triggers main pipeline and corresponding children pipelines. So far so good.
  3. Now I want to trigger ONLY trigger_a on XYZ tag. I go to dashboard → CI/CD → pipelines → Run pipeline, selecting tag XYZ and click Run pipeline. However it executes ALL triggers (trigger_a, trigger_b, trigger_c and so on). I need a way to run only child pipeline, not main.

If you want to say what should / should not run when you create a pipeline via the dashboard, you need to use $CI_PIPELINE_SOURCE

Something like this:

trigger_b:
  stage: triggers
  trigger:
    include: b/.gitlab-ci.yml
    strategy: depend
  rules:
    - if '$CI_COMMIT_BRANCH == "develop"'
      when: never
   - if '$CI_PIPELINE_SOURCE == "web"'
     when: never
    - changes:
        - b/**/*

Thank you a lot @snim2, it’s much closer to something I looked at and give me some options to achieve my goal. The problem with that solution is it’s hardcoded in pipeline (so if I decide to run only trigger_b it’s not possible with it).
Are you aware of possibilites of passing some variable during the web/api pipeline run? I could write a rule that depends on such variable, like

trigger_a:
  stage: triggers
  trigger:
    include: a/.gitlab-ci.yml
    strategy: depend
  rules:
    - if '$MY_VARIABLE is not null and $MY_VARIABLE != "trigger_a"'
      when: never
    - changes:
        - a/**/*

trigger_b:
  stage: triggers
  trigger:
    include: b/.gitlab-ci.yml
    strategy: depend
  rules:
    - if '$MY_VARIABLE is not null and $MY_VARIABLE != "trigger_b"'
      when: never
    - changes:
        - b/**/*

Sure. If you are starting the pipeline from the web interface, there’s a text-box where you can enter the name and value of a variable.

If you’re starting the pipeline any other way, that variable needs to be in your CI env vars, in your settings Settings ->CI/CD->Variables.