Reputation: 313
I am totally new to gitlab pipelines so I'm not really sure what the best way of doing this would be. I've read about submodules and dependencies, triggering other pipelines, but I I'm having a hard time understanding what would help with what I am trying to achieve here.
I have project_b that is a submodule of project_a. In project_b's .gitlab-ci.yml, project_a is currently being cloned, and then project_b is moved to where the submodule normally sits in project_a:
...
default:
...
before_script:
- git clone (project_a)
- mv project_a /src
- rm -rf /src/submodules/project_b/*
- mount --bind /src/submodules/project_b
...
This is because project_b is dependent on project_a.
Though, from what I understand, that means project_b is downstream from project_a.
I don't want to have to clone the whole project_a repo every time that I run the project_b pipeline.
I've seen plenty of info about triggering downstream pipelines for dependent projects, but the only thing I could find that seemed like it related to my case here was this question asked awhile ago about gitlab lacking the feature to trigger an upstream pipeline instead: Upstream triggering in Gitlab-CI aka pipeline dependencies
Has this feature been added? Because I sure can't find any info online. Otherwise, any suggestions as to how I could get around cloning the entire project_a repo? I might be totally off here, but one thing I was wondering is if there might be some way that I could have project_b trigger a specific pipeline for project_a that only does what I need it to do to test project_b?
Any advice would be appreciated, thanks!
Upvotes: 3
Views: 6145
Reputation: 753
Gitlab CI/CD multi-project pipelines have no intrinsic notions of upstream and downstream, so you can make a pipeline that triggers another pipeline just by referencing the project name in the trigger
keyword:
# inside project B .gitlab-ci.yml
# this stage will trigger project A pipeline to run
merge_requests:
stage: test
trigger: my/project_a
You can also use the rules
keyword to run specific stages in the downstream pipeline.
# in project A .gitlab-ci.yml
# this will never run when triggered by project B
merge_requests:
stage: test
script: echo "test some things"
rules:
- if: '$CI_PIPELINE_SOURCE == "trigger"'
when: never
# this stage will always run when triggered by project B
merge_request_downstream:
stage: test
rules:
- if: '$CI_PIPELINE_SOURCE == "trigger"'
script: echo "test some specific project B things"
So you can put your project B specific tests in the script for merge_request_downstream
. Hopefully that answers your question. I'm not quite sure that's better than just cloning project A in your project B script, but this is how you would accomplish it with multi-project pipelines.
Upvotes: 5