2

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.

2 Answers 2

2

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:

Sign up to request clarification or add additional context in comments.

10 Comments

I am already using this GIT_SUBMODULE_STRATEGY: recursive and it does say that it is updating modules but doesn't seem to do anything. And I tried to install few things with docker but the problem is even docker command is not working with this image it give this error docker : The term 'docker' is not recognized as the name of a cmdlet,
Can you add your gitlab-ci.yml file with the gitlab and runner version? And, gitlab run the script instruction inside the container, it's why you doesn't have docker. You can check one of the dockerfile from my link to see how git is installed and try to do the same in the before_script
I am posting the very basic version of my yml file in the question that I am trying to run. Please check
I add more instruction about git on windows, can you add the gitlab version and the gitlab-runner version too?
Thanks Man!! It worked :) Upvoted and selected your answer :) Just two questions, why didn't this line work [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 and why didn't path got set with this, - setx /M PATH $('c:\mingit\cmd;{0}' -f $env:PATH)
|
0

You can use cake script which will handle other .net build process as well and you can create reusable task https://cakebuild.net/dsl/git/

Comments

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.