Ci always output "Failed: Needed a single revision"

Hello,
I have a problem with the Ci/Cd in GitLab. It always output the following message:

Running with gitlab-runner 11.5.1 (7f00c780)
  on <Runner Name> ca5ecb8a
Using Shell executor...
Running on <Runner Name>...
Fetching changes...
HEAD is now at 313c12b Edited .gitlab-ci.yml
From <URL to submodule>
   313c12b..17c0a3e  master     -> origin/master
Checking out 17c0a3e8 as master...
Updating/initializing submodules recursively...
Synchronizing submodule url for 'AppSettingsHelper'
Synchronizing submodule url for 'BackupEmailParser'
Synchronizing submodule url for 'ConsoleInputManager'
Synchronizing submodule url for 'ConsoleOutputManager'
Synchronizing submodule url for 'DatabaseManager'
Synchronizing submodule url for 'ImapDownloader'
Entering 'AppSettingsHelper'
Entering 'BackupEmailParser'
Entering 'ConsoleInputManager'
Entering 'ConsoleOutputManager'
Entering 'DatabaseManager'
Entering 'ImapDownloader'
Entering 'AppSettingsHelper'
Entering 'BackupEmailParser'
HEAD is now at bc8ce28 Edited Summarys, Updated ConsoleOutputManager
Entering 'ConsoleInputManager'
HEAD is now at 27d126f Updated ConsoleOutputManager
Entering 'ConsoleOutputManager'
HEAD is now at 5339188 Remvoed spelling mistakes
Entering 'DatabaseManager'
HEAD is now at bafdd77 Updated ConsoleOutputManager
Entering 'ImapDownloader'
HEAD is now at 7266a10 Updated ConsoleOutputManager and DatabaseManager
fatal: Needed a single revision
Unable to find current revision in submodule path 'AppSettingsHelper'
ERROR: Job failed: exit status 1

I used the same .gitlab-ci.yml file as in all projects. The code of my .gitlab-ci.yml is the following:

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  PROJECT_NAME: 'BackupEmailReceiver'

stages:
  - build

DebugBuild:
  only:
    - pushes
    - branches
  tags:
    - csharp
  stage: build
  script:
  - nuget restore
  - C:\'Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin'\MSBuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Debug $BUILD_PROJECT.sln
  artifacts:
    paths:
    - '.\$PROJECT_NAME\bin\Debug'
    name: "$PROJECT_NAME-Debug"
    expire_in: 4 weeks

ReleaseBuild:
  only:
    - tags
  tags:
    - csharp
  stage: build
  script:
  - nuget restore
  - echo "$CI_COMMIT_REF_NAME"
  - C:\'Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin'\MSBuild.exe /maxcpucount /nologo /property:Configuration=Release $BUILD_PROJECT.sln
  artifacts:
    paths:
    - '.\$PROJECT_NAME\bin\Release'
    name: "$PROJECT_NAME-Release"
1 Like

Did you find a solution for this? I’m running into the same problem.

Switch in your CI config the GIT strategy from “fetch” to “clone” fix the problem for me.

It’s a workaround but not a fixing the problem

I have the same issue. It looks like https://stackoverflow.com/a/8573310

I wonder could gitlab team add some workaround for that in the runner?

Hey again. Does anyone know solution how to switch from fetch strategy to clone one if .git directory is corrupted, automatically?

Please support any ideas over there https://gitlab.com/gitlab-org/gitlab-runner/issues/4600

For me

    git submodule sync --recursive
    git submodule foreach --recursive git fetch
    git submodule update --init --recursive

in before_script section (with GIT_SUBMODULE_STRATEGY variable removed) do the job.