I was reading Downstream pipelines | GitLab
I couldn’t find a way to trigger one specific job from my project to another project.
trigger:
project: myproject/myrepo/.gitlab-ci.yaml
branch: main
strategy: depend
I can use above to create my downstream pipeline but this triggers all the job. If I have lets say 3 jobs here then I just want to trigger one job.
botkero
2
As far as I see, trigger
does have no option to specify one job.
So you would have to use rules
plus CI_PIPELINE_SOURCE
.
e.g., for myproject/myrepo/.gitlab-ci.yaml
:
my-job:
script:
- echo "Hello World"
rules:
- if: $CI_PIPELINE_SOURCE == "parent"
my-build:
script:
- echo "Hello GitLab
- If you run this inside
myproject
, then only my-build
will be executed.
- If you run this via a
trigger
, then only my-job
gets executed.
Hopefully, that will help you out.
nico-i
3
@botkero both jobs will run in your example, when the pipeline is started via a trigger
.
However, only my-build
will run when the pipeline trigger is NOT a downstream pipeline.
The following would behave as you suggested.
my-job:
script:
- echo "Hello World"
rules:
- if: $CI_PIPELINE_SOURCE == "parent"
my-build:
script:
- echo "Hello GitLab"
rules:
- if: $CI_PIPELINE_SOURCE != "parent"
Hi nico-i
Yes, you’re absolutely right.
- If you run this via a
trigger
, then only my-job
gets executed.
This is wrong. I suspect I typed a little too fast here. Thank you for the correction.
Pragmatically, just move the remote pipeline content you want to explicitly invoke into its own foo.gitlab-ci.yml file and then invoke it directly:
job:
trigger:
include:
- project: myproject/myrepo
file: .gitlab/minimal.yml