39

I registered a GitLab Runner on multiple projects. The runners of each project work fine, except for one project. First time I registered the runner, it worked.
But after I commit/push some changes, an error occurs and the job failed.
I saw some solutions that upgrading the Git version solved a problem, but I don't think so. Because all the runners work fine except this one project.

  • Server OS: CentOS 7
  • Git: 1.8.3.1

First time registered runner:

>Running with gitlab-runner 11.9.2 (...)
  on (...)
Using Shell executor...
Running on localhost.localdomain...
Initialized empty Git repository in /home/gitlab-runner/(...)/.git/
Clean repository
Fetching changes with git depth set to 50...
Created fresh repository.
From https://gitlab.com/(...)
 * [new branch]      master     -> origin/master
Checking out (...) as master...
Skipping Git submodules setup
$ echo "> gitlab-ci started"
> gitlab-ci started
$ cd /home/(..)
$ echo "> git pull started"
> git pull started
$ git pull
remote: Total 0 (delta 0), reused 0 (delta 0)
Already up-to-date.
Job succeeded

Second commit/pull, then

>Running with gitlab-runner 11.9.2 (...)
  on (...)
Using Shell executor...
Running on localhost.localdomain...
Reinitialized existing Git repository in /home/gitlab-runner/(...)/.git/
Clean repository
Fetching changes with git depth set to 50...
fatal: remote origin already exists.
fatal: git fetch-pack: expected shallow list
ERROR: Job failed: exit status 1

Edit: here is my .gitlab-ci.yml file:

stages:
- deploy

deploy_to_master:
  stage: deploy

  script:
  - echo "> gitlab-ci started"
  - cd /home/www/dir
  - echo "> git pull started"
  - git pull
  - echo "> permission set"
  - chmod 707 -R ./data/
  - chmod 707 -R ./plugin/nice/
  - chmod 707 ./favicon.ico
  - echo "> server reload(=httpd -k graceful)"
  - systemctl reload httpd
  
  only:
  - master

  tags:
  - tags
6
  • Can you share the .gitlab-ci.yml content? Commented Jun 20, 2019 at 11:21
  • @Gien Thomas I added my .gitlab-ci.yml. nothing special. just connect & pull. Commented Jun 24, 2019 at 0:12
  • Hi , gitlab runner will run /home/gitlab-runner/. But in the gitlab.ci.yml file you tried to pull the code in /home/www/dir. Commented Jun 24, 2019 at 4:38
  • try going in to gitlab-runner source folder and running the git pull in there. so then you can have a clear idea. please let me know whats the result. Commented Jun 24, 2019 at 4:43
  • I tried pulling in gitlab-runner directory.(/home/gitlab-runner/builds/(token)/0/user/dir) but it worked same as before. Error occurs before run script part in .gitlab-ci.yml. Commented Jun 25, 2019 at 1:09

9 Answers 9

77

There are a few options to fix this. The problem is the version of git on your runner is too old. And sometimes you can't update git on the runner.

Options to fix:

  1. Upgrade to a newer version of git on the runner.

  2. In .gitlab-ci.yml, use the option to git clone:

variables:
  GIT_STRATEGY: clone
  1. Configure Gitlab, change Git strategy for pipelines of the project to "git clone".

    3.1. In the Gitlab web gui,

    3.2. go to your project,

    3.3. then: "Settings -> CI / CD -> General pipelines".

    3.4. Change the options for:

    • "Git strategy for pipelines" to: "git clone"
    • "Git shallow clone" to: 0
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks much, option #3 saved my life, since there were troubles related to updating git on my runner.
This should be the accepted answer, thank you very much!
"4." would be to set the strategy on just the runner (not entire the project) via environment = ["GIT_STRATEGY=clone"] within the [[runners]] stanza of the runner's config.toml. If you have multiple runners and only some have this problem, then this variant allows other runners to continue to use the more efficient "fetch" strategy.
Option 3 did the trick for me as well. less expensive than asking to upgrade the git version on our servers.
55

Centos 7 ships with git version 1.8.3.1 . This version doesn't support commands like git fetch-pack . To fix this problem, you could update git on your server from the IUS repository. update git on Centos 7 to version 2 from third-party IUS repo

$ git --version
git version 1.8.3.1
sudo yum -y install https://packages.endpointdev.com/rhel/7/os/x86_64/endpoint-repo.x86_64.rpm
sudo yum install git

1 Comment

Helpful note: running sudo yum remove git* will also remove gitlab-runner. Skip this step; it's not needed. Install the repo and sudo yum install git, and it will replace the old version with the newer one.
7

You can go around this problem without upgrading git at all:

1. Clone Strategy

Set in .gitlab-ci.yml:

variables:
  GIT_STRATEGY: clone  

Now every change you make will trigger re-cloning the project, avoiding the need of the problematic git fetch-pack command.

2. Manually Remove Project Directory (not recommended)

Remove manually the build directory from gitlab-runner server, so it will have to clone it again.
For project testgroup/testproject, run:
careful with rm commands!

rm -rf /home/gitlab-runner/builds/UwnzuxxL/0/testgroup/testproject  

Notice that after builds directory you have a random string that will be different from this example.

Comments

5

Check value in your project's CI/CD settings on gitlab.com. If there is any value in 'git shallow clone' remove it and save changes. Now your pipeline will work as expected. see image

2 Comments

mine was the other way around.
I had git fetch on, and got the error - error: Could not read aaabbb - fatal: unresolved deltas left after unpacking - fatal: unpack-objects failed and after changing to clone . it worked!
2

I had a similar issue, and I had to update Git. Centos 7 comes with git-1.8.x which has limitations around gitlab-ci.

Upgrade your git, based on this guide.

1 Comment

Understand that by updating git from an outside source, you are accepting a risk of delayed updates and incompatibilities. Ensure you're okay with this or find a better solution for the Enterprise.
2

This worked for me.

3.1. In the Gitlab web gui,

3.2. go to your project,

3.3. then: "Settings -> CI / CD -> General pipelines".

3.4. Change the options for:

"Git shallow clone" to: 0

Comments

0

Add GIT_STRATEGY=clone to "config.toml".

/etc/gitlab-runner/config.toml:

...
[[runners]]
  ...
  environment = ["GIT_STRATEGY=clone"]

Comments

-1

I made a new project and, finally, it works fine. I don't know why the other one didn't work. If the same problems occurs like mine, don't get too serious: Just make a new gitlab project. It is good for your mental well-being.

Comments

-4

rm -fr /home/gitlab-runner/(...) , clean then exists repository

2 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
"then exists repository" - if you run rm -rf, the specific folder is removed. How could anything exist directly after removing a folder?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.