GIT_DEPTH not following precedence rules when set in .gitlab-ci.yml
Summary
When GIT_DEPTH
is specified as a variable in .gitlab-ci.yml
the value specified there is applied to the git fetch
operation regardless of any different values set in pipeline trigger or project CI/CD variables. This is in violation of the CI/CD Variable Precedence rules.
Reported by customer in ZD internal link
Steps to reproduce
Create a simple job with differing GIT_DEPTH
values set in .gitlab-ci.yml
and as a project variable. Run the pipeline and check the job output for the Fetching changes with git depth set to X
message. The value of X
matches that set in .gitlab-ci-yml
.
.gitlab-ci.yml
variables:
CI_DEBUG_TRACE: 1
GIT_DEPTH: 5
build1:
stage: build
script:
- echo "In build"
Actual behavior
Job log outputs:
Fetching changes with git depth set to 5...
Expected behavior
Job log outputs:
Fetching changes with git depth set to 2...
Relevant logs and/or screenshots
job log
Running with gitlab-runner 14.4.0 (4b9e985a)
on jfarmiloe-v14-gl-run-geo-runner-shell AuT3A3NT
Resolving secrets
00:00
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
+ set -eo pipefail
+ set +o noclobber
+ :
+ eval 'echo "Running on $(hostname)..."
'
+++ hostname
++ echo 'Running on jfarmiloe-v14-gl-run-geo-runner...'
Running on jfarmiloe-v14-gl-run-geo-runner...
+ exit 0
Getting source from Git repository
00:01
+ set -eo pipefail
+ set +o noclobber
+ :
mkdir -p "/home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd.tmp"
export CI_DEBUG_TRACE=1
export GIT_DEPTH=5
export GIT_DEPTH=2
++ echo 'Fetching changes with git depth set to 5...'
Fetching changes with git depth set to 5...
++ mkdir -p /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd.tmp/git-template
++ git config -f /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd.tmp/git-template/config fetch.recurseSubmodules false
++ git config -f /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd.tmp/git-template/config http.https://jfarmiloe-v14-gl-run-geo-gitlab.sr.gitlab.support.sslCAInfo /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd.tmp/CI_SERVER_TLS_CA_FILE
++ rm -f /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd/.git/index.lock
++ rm -f /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd/.git/shallow.lock
++ rm -f /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd/.git/HEAD.lock
++ rm -f /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd/.git/hooks/post-checkout
++ rm -f /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd/.git/config.lock
++ git init /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd --template /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd.tmp/git-template
Reinitialized existing Git repository in /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd/.git/
++ cd /home/gitlab-runner/builds/AuT3A3NT/0/root/basic-cicd
++ git remote add origin https://gitlab-ci-token:[MASKED]@jfarmiloe-v14-gl-run-geo-gitlab.sr.gitlab.support/root/basic-cicd.git
++ git remote set-url origin https://gitlab-ci-token:[MASKED]@jfarmiloe-v14-gl-run-geo-gitlab.sr.gitlab.support/root/basic-cicd.git
++ git -c 'http.userAgent=gitlab-runner 14.4.0 linux/amd64' fetch origin +1a269360eef0f878c556eadf6299b07334f5cc8e:refs/pipelines/595 +refs/heads/main:refs/remotes/origin/main --depth 5 --prune --quiet
Environment description
Reproduced on Gitlab.com shared runners using docker executor and on self-managed runner using shell executor.
Used GitLab Runner version
Running with gitlab-runner 14.4.0 ( 4b9e985a)
Running with gitlab-runner 14.8.0~beta.44.g57df0d52 ( 57df0d52)
Possible fixes
Fix Ci::BuildRunnerPresenter
to present the correct git_depth when presented with Entities::Ci::JobRequest::Response
Create a follow-up issue for the potential deprecation of GIT_DEPTH