0

I am trying to automate a build but I can't get through the test stage. I have found a template for flutter app for the ".gitlab-ci.yml" and set up a local runner with shell.

I already have included the git path to the environment and I can use git in the powershell. I can't get the job to succeed. It doesn't seem to find the git command.

Here is the .gitlab-ci.yml file:

code_quality:
  stage: test
  image: "cirrusci/flutter:1.22.5"
  before_script:
    - pub global activate dart_code_metrics
    - export PATH="$PATH":"$HOME/.pub-cache/bin"
  script:
    - metrics lib -r codeclimate  > gl-code-quality-report.json
  artifacts:
    reports:
      codequality: gl-code-quality-report.json

This is the config of the runner:

concurrent = 2
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "local laptop"
  url = deleted
  token = deleted
  executor = "shell"
  shell = "powershell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]

And this is the error:

Running with gitlab-runner 14.9.1 (bd40e3da)
  on local laptop yHX7nELF
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on LT...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
& : Die Benennung "git" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines ausf�hrbaren 
Programms erkannt. �berpr�fen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und 
wiederholen Sie den Vorgang.
In C:\WINDOWS\TEMP\build_script2239212065\script.ps1:221 Zeichen:3
+ & "git" "config" "-f" "C:\GitLab-Runner\builds\yHX7nELF\0\ads\kurt-ca ...
+   ~~~~~
    + CategoryInfo          : ObjectNotFound: (git:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
Uploading artifacts for failed job
00:00
Version:      14.9.1
Git revision: bd40e3da
Git branch:   14-9-stable
GO version:   go1.17.7
Built:        2022-03-22T21:26:32+0000
OS/Arch:      windows/amd64
Uploading artifacts...
Runtime platform                                    arch=amd64 os=windows pid=15980 revision=bd40e3da version=14.9.1
WARNING: gl-code-quality-report.json: no matching files 
ERROR: No files to upload                          
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit status 1

Thank you in advance!

1 Answers1

1

Based on the error message, it sounds like git isn't installed or available to the GitLab Runner. You will need to install git if you have not, add it to the PATH variable, and restart Powershell. See the following post, as I believe it is relevant to your situation: Git is not recognized in Windows gitlab ci.

The root of this problem could also be a PATH issue. Add Get-Item Env:PATH to your scripts section and inspect the output of a GitLab job to verify PATH is being set correctly. Relevant post: How to print env vars in PowerShell?

code_quality:
  stage: test
  image: "cirrusci/flutter:1.22.5"
  before_script:
    - pub global activate dart_code_metrics
    - export PATH="$PATH":"$HOME/.pub-cache/bin" # <- This doesn't seem right
    - $Env:Path += ";$HOME\.pub-cache\bin" # <- Try this, instead
  script:
    - Get-Item Env:Path  # <- output contents of PATH variable
    - metrics lib -r codeclimate  > gl-code-quality-report.json
  artifacts:
    reports:
      codequality: gl-code-quality-report.json
Richard
  • 2,226
  • 2
  • 19
  • 35
  • Thank you very much it solved those 2 problems. I followed also the other posts that you kindly pasted: - I reinstalled git in C: as an admin. (it was only in my user) - Also modified the export line as you suggested Now the new problem is: it doesn't find the "pub" command. I will search it in other posts. – Hector Sanchez Tejada Apr 25 '22 at 13:00