2

I am trying to trigger a pipeline from another pipeline using '$CI_JOB_TOKEN' (https://docs.gitlab.com/ee/ci/triggers/README.html#when-used-with-multi-project-pipelines). The second pipeline is getting triggered, but it is always executing the build stage of the second pipeline. Which means it is only executing those jobs with 'except: - triggers'. I wanted to execute jobs with 'only: -triggers'

trigger-child-pipeline:
  stage: trigger-child-pipeline
  only:
     - triggers
  tags:
      - runner
  script:
      - curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=my_branch https://gitlab.mycompany.com/api/v4/projects/1234/trigger/pipeline

I wanted to execute jobs with 'only trigger' tag in the child pipeline. Am I missing anything? I couldnt figure out anything from the documentation(https://docs.gitlab.com/ee/ci/triggers/README.html#when-used-with-multi-project-pipelines).

Thanks

Shemeem
  • 198
  • 2
  • 14
  • Could you share `child-pipeline` yaml? `only: -triggers` should be in child pipeline configuration, not in parent. – makozaki Mar 02 '20 at 14:11
  • Yes, I have jobs with 'only: triggers' in child pipeline, these jobs are not getting triggered instead of jobs with 'except: triggers' are getting triggered. – Shemeem Mar 03 '20 at 07:27
  • Share both parent and child job configuration. It doesn't make sense that job with `except: triggers` runs when launched with trigger. – makozaki Mar 03 '20 at 07:36
  • This child pipeline is working as expected when I trigger it directly - jobs with 'only: triggers' are getting triggered – Shemeem Mar 03 '20 at 07:49
  • In fact If I am triggering the child pipeline with the same code ' - curl --request POST --form "token=" --form "ref=my_branch" https://gitlab.mycompany.com/api/v4/projects/1234/trigger/pipeline, with trigger token it is working as expected. ' – Shemeem Mar 03 '20 at 08:14

1 Answers1

2

Try again with GitLab 13.4 (September 2020)

You can check if its latest feature will make your use-case easier, with a different approach:

Child pipelines can now trigger their own child pipelines

When using parent/child pipelines, it is now possible for child pipelines to trigger their own child pipelines. This added depth can be useful when you want the flexibility to generate a variable number of child pipelines.

Before, with a parent/child configuration, every child pipeline needed a trigger job manually defined in the parent.

Now you can generate child pipelines that dynamically trigger any number of new child pipelines. If you have a monorepo, for example, you can dynamically generate a first child pipeline that itself generates a variable number of new child pipelines, based on the changes in a branch.

https://about.gitlab.com/images/13_4/parent_child_pipeline.png -- Child pipelines can now trigger their own child pipelines

See Documentation and Issue.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Is it also possible to use this with multi-project pipelines? – ddsultan May 05 '21 at 16:28
  • @ddsultan I don't think so, considering the documentation (https://docs.gitlab.com/ee/ci/parent_child_pipelines.html) mentions: "**Similarly to multi-project pipelines**, a pipeline can trigger a set of concurrently running child pipelines, but within the same project:" – VonC May 05 '21 at 17:55
  • Thanks. I thought so but checked myself job succeeds but trigger is not done. I used trigger API instead of YML – ddsultan May 05 '21 at 18:25