How to run git commands in .net solution build pipeline in gitlab

by Pawan Nogariya   Last Updated May 22, 2020 19:26 PM - source

I have a .net repository which is dependent on another repository so I am using the other repository as submodule.

I am using this docker image to build the repository

image: mcr.microsoft.com/dotnet/framework/sdk

But to use the submodule I have to get the latest of the submodule and that can be done using the git commands like this

before_script:
  - git submodule sync --recursive
  - git submodule update --init --recursive

but the git command is not available in the docker image and so it fails saying git is not recognized

Can anyone help me what should be done to have git available?

I have tried many things like dividing the build in two stages and try to use different docker image for git etc. but nothing is exactly working for my requirement.

Update

This is .gitlab-ci.yml file including the solution that jmaitrehenry suggested in his answer

stages:
   - build


variables:
    GIT_SUBMODULE_STRATEGY: recursive

before_script:
    - docker build -t git-for-windows-issue

# Build
Build:
  image: mcr.microsoft.com/dotnet/framework/sdk
  stage: build
  script:
    - echo Ok
  only:
    - branches
  tags:
    - windows-runner
  environment:
    name: development

But that is also giving this error

docker : The term 'docker' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.



Answers 1


If your gitlab runner is not too old (v1.10+), you can add this in your pipeline:

variables:
  GIT_SUBMODULE_STRATEGY: recursive

With that, gitlab will do the sync and update for you when it clone/prepare the project.

If you can't, you will need to install git in your image. You can check this repo to help you with git on windows: https://github.com/StefanScherer/dockerfiles-windows/tree/master/git-for-windows-issue You can add this to the before_script:

before_script:
  - Invoke-WebRequest 'https://github.com/git-for-windows/git/releases/download/v2.15.1.windows.2/MinGit-2.15.1.2-busybox-64-bit.zip' -OutFile 'mingit.zip' -UseBasicParsing
  - Expand-Archive mingit.zip -DestinationPath c:\mingit ; \
  - Remove-Item mingit.zip -Force ; \
  - c:\mingit\cmd\git.exe submodule sync --recursive
  - c:\mingit\cmd\git.exe submodule update --init --recursive

Gitlab doc: https://docs.gitlab.com/ee/ci/git_submodules.html How to install git on windows:

jmaitrehenry
jmaitrehenry
May 22, 2020 18:16 PM

Related Questions