5

I have set up a GitLab pipeline, and configured a runner. The build starts when I make a commit, but fails almost immediately with the following message:

C:\GitLabRunner\builds\xxxxxxxx\0\cmac\portal>"git" "checkout" "-f" "-q" 
   "xxxxxxxxxxxxxxxxxxxxxxxxx" 

 '"git"' is not recognized as an internal or external command,
   operable program or batch file.

C:\GitLabRunner>IF 9009 NEQ 0 exit /b 9009 
ERROR: Job failed: exit status 9009

This is my .gitlab-ci.yml, which I have stripped right back to try and isolate the issue:

stages:
 - build
variables:
  CI_DEBUG_TRACE: "true"
Build:
  stage: build
  script:
     - Echo OK

The only similar issues I could find are here and here

I thought I had fixed the issue when I was getting the same message in a when trying to use git in a standard command prompt as my PATH wasn't set correctly in Environment variables.

However I have now fixed this and I am getting expected responses back from git through the command prompt, however I still get the issue when gitlab kicks off the build.

Any ideas?

Declan McNulty
  • 3,194
  • 6
  • 35
  • 54
  • 1
    Just remove the double quotes and it should be fine – Hackerman Sep 07 '17 at 17:25
  • Do you mean the quotes around this: "git" "checkout" "-f" "-q" ? That is auto generated by the gitlab build which I don't have any control over – Declan McNulty Sep 08 '17 at 07:11
  • Yes, remove them all – Hackerman Sep 08 '17 at 10:48
  • What I'm saying is I can't remove the quotes because the gitlab build generates the script and runs it, it isn't possible to remove them – Declan McNulty Sep 08 '17 at 13:29
  • Ok, just one more check.... can you open a command line and `cd` to this folder `C:\GitLabRunner\builds\xxxxxxxx\0\cmac\portal`, then run the following command in the cmd `git status`.... – Hackerman Sep 08 '17 at 14:21
  • Yes I've already done that and it recognises git both through bash and cmd – Declan McNulty Sep 08 '17 at 14:37
  • @DeclanMcNulty I am dealing with simillar problem, error message is for maven that is recognized in bash (mvn) as it is git in your case. – CAPS LOCK Sep 18 '17 at 20:14
  • I have the same problem here: https://stackoverflow.com/questions/49155380/git-is-not-recognized-in-windows-gitlab-ci – Martin Delille Mar 08 '18 at 10:12
  • One reason for "is not recognized as an internal or external command" can be that the gitlab-runner service runs as SYSTEM and the program you are trying to execute within the pipeline runs as your Windows user. I actually had this one time with `cargo`, because Rust is installed per user. – Ini Jun 14 '23 at 22:30

4 Answers4

1

After you install new applications on your buildmachine restart gitlab runner to pick up path.

GintsGints
  • 807
  • 7
  • 15
  • More generally, when you modify the environment variables you have to restart the gitlab runner to update its environment. – fkorsa May 03 '18 at 08:16
1

I use gitlab-ci with powershell as executor.
Add the git path C:\Program Files\Git\bin to $PATH fixed this problem

Til
  • 5,150
  • 13
  • 26
  • 34
ljian
  • 31
  • 3
  • In my case "C:\Program Files\Git\cmd" was already added when i installed GIT but after adding the path "C:\Program Files\Git\bin" to the PATH environment variable the issue got resolved. – Sudhanshu Shekhar Sep 20 '22 at 04:38
0

Installing Git to c:\Git instead of c:\Program Files... fixed this problem for me

ovsvolvic
  • 3
  • 1
0

Did you install git on the CI? In my .gitlab-ci.yml solved this by adding apk update && apk add git to the before_script, like so:

# Make sure to install all packages before running anything.
before_script:
  - apk update && apk add git
  - npm ci # For CI it's better to have this instead of npm install.
Daniel Danielecki
  • 8,508
  • 6
  • 68
  • 94