CI environment variables for merge request dependencies
Problem to solve
I want to make my pipelines aware of merge request dependencies, so that I can checkout upstream dependencies.
Further details
When a CI pipeline runs on my feature branch, that depends on projects in another repository, I want to integrate my changes on the feature branches that I have explicitly listed as dependencies.
If I'm using Git submodules, if I know the project and SHA, I can then simply checkout the desired SHA in the before_script
block.
Proposal
Expose the merge request dependencies in the CI environment so that a script like the following can be run in the before_script
block
CI_MERGE_REQUEST_DEPENDENCY_PROJECT_PATH_1="group/project1"
CI_MERGE_REQUEST_DEPENDENCY_MERGE_REQUEST_IID_1="3"
CI_MERGE_REQUEST_DEPENDENCY_COMMIT_SHA_1="abc123..."
CI_MERGE_REQUEST_DEPENDENCY_PROJECT_PATH_2="group/project2"
CI_MERGE_REQUEST_DEPENDENCY_MERGE_REQUEST_IID_2="2"
CI_MERGE_REQUEST_DEPENDENCY_COMMIT_SHA_2="abc123..."
# Iterate over matching environment vars
for varname in ${!CI_MERGE_REQUEST_DEPENDENCY_PROJECT_PATH*}
do
# TODO: Get the x value
# Do things like...
git -C "vendor/$CI_MERGE_REQUEST_DEPENDENCY_PROJECT_PATH_x" checkout "$CI_MERGE_REQUEST_DEPENDENCY_COMMIT_SHA_x"
done