How to specify a job when calling a child pipeline?

Hello,
In the context of creating and destroying pods in kubernetes with helm, I am trying to make use of parent-child pipelines.

Here’s the child pipeline for helm:

---
stages:
- deploy
- destroy

DeployPods:
  image: $HELM_IMAGE
  stage: deploy
  script:
  [...]
  - helm install ... my_name-$UID
  only:
    - pipelines

DestroyPods:
  image: $HELM_IMAGE
  stage: destroy
  script:
  - helm uninstall my_name-$UID
  only:
    - pipelines

Now I would like to be able to execute the job I want from the parent pipeline:

---
stages:
- deploy
- destroy

variables:
  JOB_ID: $CI_JOB_ID

Deploy:
  stage: deploy
  variables:
    UID: $JOB_ID
  trigger:
    project: path/to/helmPipeline
    branch: main
    job: DeployPods  <---- Here is the feature I'm looking for
    strategy: depend

Destroy:
  stage: destroy
  variables:
    UID: $JOB_ID
  trigger:
    project: path/to/helmPipeline
    branch: main
    job: DestroyPods  <---- Here is the feature I'm looking for
    strategy: depend

Everythinng is working fine without the keyword job, but in this case I would have to add some logic (if/else statement or rules) in the child pipeline to target the job that has to be run.
Is there a way of doing what I’m looking for ?

Thank’s in advance for help.

Hi @tpitz
set some variable in Deploy job that you will pass to child pipeline and add rules: to the child pipeline’s jobs to run only if that variable is set.

1 Like