Michal Kurz
Michal Kurz

Reputation: 2095

Error for git submodule in Gitlab CI runner - "fatal: destination path already exists and is not an empty directory."

I am trying to include a submodule into my GitLab repository. It works just fine locally, but my build pipeline fails. According to this docs entry, all I should do is use relative url and set up the GIT_SUBMODULE_STRATEGY, but it doesn't really work.

My .gitmodules:

[submodule "res/submoduleName"]
    path = res/submoduleName
    url = ../submoduleName.git

.gitlab-ci.yml:

variables:
  GIT_SUBMODULE_STRATEGY: recursive

integration-test:
  # ... 

I get the following error in my Pipeline shell:

Updating/initializing submodules recursively...
Submodule 'res/submoduleName' (https://gitlab-ci-token:[MASKED]@gitlab.com/mainProjectName/submoduleName.git) registered for path 'res/submoduleName'
fatal: destination path '/builds/_oBZKNaH/0/mainProjectName/mainProjectName/res/submoduleName' already exists and is not an empty directory.
fatal: clone of 'https://gitlab-ci-token:[MASKED]@gitlab.com/mainProjectName/submoduleName.git' into submodule path '/builds/_oBZKNaH/0/mainProjectName/mainProjectName/res/submoduleName' failed
Failed to clone 'res/submoduleName'. Retry scheduled
fatal: destination path '/builds/_oBZKNaH/0/mainProjectName/mainProjectName/res/submoduleName' already exists and is not an empty directory.
fatal: clone of 'https://gitlab-ci-token:[MASKED]@gitlab.com/mainProjectName/submoduleName.git' into submodule path '/builds/_oBZKNaH/0/mainProjectName/mainProjectName/res/submoduleName' failed
Failed to clone 'res/submoduleName' a second time, aborting
Cleaning up file based variables
00:00
ERROR: Job failed: exit code 1

What can I do to fix this problem?

Upvotes: 2

Views: 2075

Answers (1)

Michal Kurz
Michal Kurz

Reputation: 2095

The error message was misleading. The folder was empty, but GitLab runner did not have the permissions to write into it. I solved the problem by adding - chmod -R 777 res to before_script of my job.

Upvotes: 2

Related Questions