Code snippet and background
I have a workflow with multiple jobs as below:
stages:
- another
- yet-another
another-job:
stage: another
rules:
- if: $CI_PIPELINE_SOURCE == "push"
when: always
script:
- echo "Another job"
yet-another-job:
stage: yet-another
rules:
- if: $CI_PIPELINE_SOURCE == "push"
when: manual
allow_failure: true
script:
- echo "Yet another job"
If I write this in the top-level .gitlab-ci.yml
file, it works as expected. The first job is triggered on every push, the second job gets added to the pipeline and waits for the manual trigger.
Goal (what I want to do)
Now I need to add workflows for other usecases. Hence, to keep the workflows modular, I want to move the above into another yml file and trigger it using parent-child pipelines.
What I have done so far
So I move it to a file .gitlab-ci/another-workflow/.gitlab-ci.yml
, and write the following in the top-level .gitlab-ci.yml
(parent):
another-workflow:
trigger:
include: .gitlab-ci/another-workflow/.gitlab-ci.yml
allow_failure: true
What doesn’t work
But this leads to the error:
another-workflow - failed - (downstream pipeline can not be created, Pipeline will not run for the selected trigger. The rules configuration prevented any jobs from being added to the pipeline.)
What I need help with
From the documentation, I figured out that I need to specify rules
in the parent pipeline to trigger the child pipeline, but I cannot figure out what it should be.
The above example is clearly a simplified minimal working sample of my actual workflow at work. In my actual workflow, there are some dependencies and shared variables between the various jobs in the child workflow. For that reason, I want to avoid splitting up the child workflow file, if possible.
Question
Hence, I would like to setup the workflow in one of the following ways:
-
In the parent pipeline, specify:
(1) ontriggerA
, runchild.job1
(2) ontriggerB
, runchild.job2
-
In the parent pipeline, specify: “don’t ask me anything, just do as the child says”
-
Any other option?
Other information
-
Gitlab runner:
gitlab-runner 16.3.0~beta.108.g2b6048b4 (2b6048b4)
-
As you might expect from the post above :), I have read through the documentation, forum posts, stack overflow, etc. and tried out the various suggestions, that are too numerous to be listed here.
-
I have set up a sandbox repository for this purpose here: Files · another-workflow · Aravind Pai / honeycomb · GitLab. Please feel free to use it for any trials.
Thank you for your consideration. Please let me know if any further information is needed from my side.