I am facing this issue during try to deploy script with gitlab ci/cd:
Initialized empty Git repository in C:/builds/Tri.BuiV/test-gitlab-cicd/.git/
fatal: detected dubious ownership in repository at 'C:/builds/Tri.BuiV/test-gitlab-cicd'
'C:/builds/Tri.BuiV/test-gitlab-cicd' is owned by:
'S-1-5-83-1-1989435290-1148643240-1709935003-3943614564'
but the current user is:
'S-1-5-93-2-1'
To add an exception for this directory, call:
git config --global --add safe.directory C:/builds/Tri.BuiV/test-gitlab-cicd
I tried:
git config --global --add safe.directory C:/builds/Tri.BuiV/test-gitlab-cicd
But the same error, why?
I tried:
git config --global --add safe.directory C:/builds/Tri.BuiV/test-gitlab-cicd
But get the same issue.
2
Answers
If the error persists, it probably means your
git config --global
(which impacts%USERPROFILE%.gitconfig
) does not use the same account as the one running your GitLab CI/CD.If GitLab runs with a different account, it might try to access a folder initially created by you.
The GitLab pipeline itself would need to include:
This I what is being automatically added for GitLab 15.8 in MR 3538.
The solstice333 points out in the comments to
gitlab-org/gitlab-runner
issue 29022, where Kevin Navero explains:I had this as well when using an image from mcr.microsoft.com/windows/servercore:ltsc2016 as the executor, but it turned out the reason it was failing was because I was pre-creating the builds folder in the Dockerfile:
When I removed this from the Dockerfile, the git dubious ownership error went away.
(The reason I was creating this folder was because I was using the build container in local testing, and wanted the exact same path setup to be present, so I needed the folder locally too. In future I’ll create it manually though.)