Problems with CI/CD with Unity

I’ve been trying to follow this to learn how to do CI/CD with Unity and Gitlab. https://engineering.etermax.com/continuous-integration-in-unity-with-gitlab-ci-cd-part-1-e902c94c0847

But I’m having trouble with my path to Unity in Windows

Here is my .yml file. I think my path to unity.exe is wrong. Can someone tell me the correct way to format it for Windows?

stages:
  - test
  - build
  - deploy
unit-test:
  script: "E:\\Unity Editors\\2020.1.1f1\\Editor\\Unity.exe -batchmode -projectPath . -runTests -testPlatform editmode -logFile -testResults ./unit-tests.xml"
  stage: test
  tags:
    - unity
unity-build:
  script: "echo 'Building...'"
  stage: build
  tags:
    - unity
playstore:
  script: "echo 'Deploying...'"
  stage: deploy
  tags:
    - unity

This is the error I get when the job is run in Gitlab

E:\Unity Editors\2020.1.1f1\Editor\Unity.exe -batchmode -projectPath . -runTests -testPlatform editmode -logFile -testResults ./unit-tests.xml

20E:\Unity : The term ‘E:\Unity’ is not recognized as the name of a cmdlet, function, script file, or operable program.

21Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

22At C:\WINDOWS\TEMP\build_script328594296\script.ps1:201 char:1

23+ E:\Unity Editors\2020.1.1f1\Editor\Unity.exe -batchmode -projectPath …

24+ ~~~~~~~~
25 + CategoryInfo : ObjectNotFound: (E:\Unity:String) [ ], CommandNotFoundException
26 + FullyQualifiedErrorId : CommandNotFoundException

Your first problem is gitlab runner is using PowerShell not the cmd console
script: Start-Process "C:\Program Files\Unity\Hub\Editor\2020.1.7f1\Editor\Unity.exe" -ArgumentList "-batchmode -projectPath . -runTests -testPlatform editmode -logFile -testResults ./unit-tests.xml"

This works, in that it uses unity to run the tests and produces the test results file.
But
Gitlab doesn’t see the results file, and reports the job as a success.

This is as far as I have got following the same Mac based tutorial.

1 Like
stages:
  - test
  - build
  - deploy
unit-test:
  stage: test
  variables:
    ErrorActionPreference: Stop
  script:
    - Start-Process "C:\Program Files\Unity\Hub\Editor\2020.1.7f1\Editor\Unity.exe" -ArgumentList "-batchmode -projectPath . -runTests -testPlatform editmode -logFile -testResults ./unit-tests.xml" -Wait | Out-Default
    - '[xml]$xml = Get-Content -PATH ./unit-tests.xml'
    - $result = $xml.SelectSingleNode("//test-run.result").InnerText
    - if ("Passed" -ne $result) { throw }
  artifacts:
    when: always
    paths:
      - unit-tests.xml
    reports:
      junit: unit-tests.xml
  tags:
    - unity
unity-build:
  stage: build
  script: echo 'Building...'
  tags:
    - unity
playstore:
  stage: deploy
  script: echo 'Deploying...'
  tags:
    - unity

The ErrorActionPreference: Stop comes from here:; Windows PowerShell failed still marks job successful (#3194) · Issues · GitLab.org / gitlab-runner · GitLab
The 3 lines after Start-Process just open the results file and check the result attribute of the root element of the xml.
Not particularly elegant, but it works.
Pretty sure the Output-Default flag is redundant.
Hope this helps.
My next steps will be the build step and deploying to itich.io with their refinery platform.

1 Like
  1. - $result = $xml.SelectSingleNode('test-run').result
1 Like