Gitlab runner cant perform git command

I’ve facing this problem for the CI/CD pipeline, it always failed in git command resulting error of

fatal: detected dubious ownership in repository at ‘/home/adadev/docker_folder//…’

I’ve tried adding safe.directory “*” in the runner env and some git command finally able to run (such as, git branch)

But the problem still remains when im about to git stash. The job just forced ended without any error log/ traces even if I see the full raw

Cleaning up project directory and file based variables00:00

[39](https://repo.polytron.co.id/ADA/commercial/digitec-tv/-/jobs/5826#L39)ERROR: Job failed: exit status 1

Gitlab runner version : 16.1.0


Updates:

  • I tried running gitlab-runner in debug mode and using command sudo gitlab-runner --debug run
  • its working and the CI build success
  • when I stop and try to run sudo gitlab-runner start the job keep failing again

Why do you run git stash?

Have you tried checking repository ownership and permissions and reviewing the safe.directory configuration in the runner environment. Also try avoiding using debug mode for regular use.

I have the same problem. Running a git command in a CI workflow is a normal thing.

No answer to this problem in 2 years?

is it though?

Examples for running git commands in pipelines:

  • buildnumber-maven-plugihn
  • building releases and creating a tag
  • Search for workflows of open-source projects (e.g. on GitHub) and you will find many examples

However, lets be constructive and focus on the actual problem…

I digged deeper and now the problem totally makes sense. Before I was wondering why GitLab CI can checkout the code with git and then later in the build working on that cloned repo it does not have git. But the thing is that you are using image tag to define a container where the build job is running on. GitLab CI just mounts the cloned repo into the container so it is available but with your container you are in charge of installing git.

So as a solution:

  • either choose an image that brings git
  • or add before_script that installs git

Problem solved.