Updating Submodule URL via CI/CD not respected
Summary
A customer wants to update their submodule URL within their CI Job without having to commit changes to their .gitmodules file. Our hooks:pre_get_sources_script documentation suggests using this to Adjust the Git configuration.
I suggested using hooks:pre_get_sources_script to execute git config --global submodule.<name>.url URL
before the submodule is cloned. However the CI job does not respect the changes and the job still attempts to clone the submodule using the old URL.
Steps to reproduce
- Add a submodule to a project
- configure your .gitlab-ci.yml file to use hooks:pre_get_sources_script and execute
git config --global submodule.<name>.url URL
- Run a new pipeline
- Observe that despite executing
git config --global submodule.<name>.url URL
, the CI Job still attempts to clone the submodule using the URL defined in .gitmodules instead of the URL defined in the git config.
NOTES:
When updating the submodule URL in the hook, git config submodule.<NAME>.url
shows the updated URL:
Running pre sources script
$ git config --global submodule.<NAME>.url <NEW-URL>
$ git config submodule.<NAME>.url
https://gitlab.com/path/to/updated/url.git
However when running the same git config submodule.<NAME>.url
command in the script
section, it is still showing the old submodule URL rather than the updated one.
$ git config submodule.<NAME>.url
https://gitlab.com/path/to/old/url.git
This results in the old submodule URL being cloned rather than the updated submodule URL.
.gitlab-ci.yml
submodule-job:
stage: test
hooks:
pre_get_sources_script:
- echo 'Running pre sources script'
- git config --global submodule.<name>.url <NEW-URL>
- git config submodule.<NAME>.url
script:
- git config submodule.<NAME>.url
Actual behavior
Updating the submodule url in the global git config via hooks:pre_get_sources_script is not respected when the submodule is cloned. The customer confirms this works locally.
Expected behavior
Updating the submodule url in the global git config via hooks:pre_get_sources_script is respected and the submodule is cloned using this updated URL.
Relevant logs and/or screenshots
job log
Running with gitlab-runner 16.3.0~beta.108.g2b6048b4 (2b6048b4)
on green-2.saas-linux-small-amd64.runners-manager.gitlab.com/default ns46NMmJ, system ID: s_85d7af184313
feature flags: FF_USE_IMPROVED_URL_MASKING:true, FF_RESOLVE_FULL_TLS_CHAIN:false
Resolving secrets
00:00
Preparing the "docker+machine" executor
00:19
Using Docker executor with image ruby:3.1 ...
Pulling docker image ruby:3.1 ...
Using docker image sha256:1071c7e93914582ffc858691072157b681d5f59808059937aff0f7a34366c701 for ruby:3.1 with digest ruby@sha256:f79e08b89a622210d611eab0737ad4599d7aa74a019a2f76b0a9438f19094611 ...
Preparing environment
00:05
Running on runner-ns46nmmj-project-45693952-concurrent-0 via runner-ns46nmmj-s-l-s-amd64-1697818281-34985243...
Getting source from Git repository
00:02
$ echo 'Running pre sources script'
Running pre sources script
$ git config --global submodule.submodule.url https://gitlab.com/rkelly_ultimate_group/ryan-test-subgroup/submodule-test/submodule2.git
$ git config submodule.submodule.url
https://gitlab.com/rkelly_ultimate_group/ryan-test-subgroup/submodule-test/submodule2.git
Fetching changes with git depth set to 20...
Initialized empty Git repository in /builds/rkelly_ultimate_group/ryan-test-subgroup/submodule-test/submodule-project/.git/
Created fresh repository.
Checking out 407b6b70 as detached HEAD (ref is main)...
Updating/initializing submodules recursively with git depth set to 20...
Synchronizing submodule url for 'submodule'
Cloning into '/builds/rkelly_ultimate_group/ryan-test-subgroup/submodule-test/submodule-project/submodule'...
Submodule path 'submodule': checked out 'e263657b155b56b84900468a2330d28e1539a783'
Updated submodules
Entering 'submodule'
Entering 'submodule'
$ git remote set-url origin "${CI_REPOSITORY_URL}"
Executing "step_script" stage of the job script
00:00
Using docker image sha256:1071c7e93914582ffc858691072157b681d5f59808059937aff0f7a34366c701 for ruby:3.1 with digest ruby@sha256:f79e08b89a622210d611eab0737ad4599d7aa74a019a2f76b0a9438f19094611 ...
$ git config submodule.submodule.url
git@gitlab.com:gitlab-gold/ryan-test-subgroup/submodule-test/submodule.git
Cleaning up project directory and file based variables
00:01
Job succeeded</code></pre>
Environment description
This occurs on GitLab.com shared runners