Search Unity

Problems with CI/CD with Unity

Discussion in 'Testing & Automation' started by tchris, Dec 22, 2020.

  1. tchris

    tchris

    Joined:
    Oct 10, 2012
    Posts:
    133
    I've been trying to follow this to learn how to do CI/CD with Unity and Gitlab. https://engineering.etermax.com/con...n-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?


    Code (CSharp):
    1. stages:
    2.   - test
    3.   - build
    4.   - deploy
    5. unit-test:
    6.   script: "E:\\Unity Editors\\2020.1.1f1\\Editor\\Unity.exe -batchmode -projectPath . -runTests -testPlatform editmode -logFile -testResults ./unit-tests.xml"
    7.   stage: test
    8.   tags:
    9.     - unity
    10. unity-build:
    11.   script: "echo 'Building...'"
    12.   stage: build
    13.   tags:
    14.     - unity
    15. playstore:
    16.   script: "echo 'Deploying...'"
    17.   stage: deploy
    18.   tags:
    19.     - 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
     
  2. davethemac

    davethemac

    Joined:
    Jan 8, 2020
    Posts:
    3
    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.
     
    io-games likes this.
  3. davethemac

    davethemac

    Joined:
    Jan 8, 2020
    Posts:
    3
    Code (CSharp):
    1. stages:
    2.   - test
    3.   - build
    4.   - deploy
    5. unit-test:
    6.   stage: test
    7.   variables:
    8.     ErrorActionPreference: Stop
    9.   script:
    10.     - 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
    11.     - '[xml]$xml = Get-Content -PATH ./unit-tests.xml'
    12.     - $result = $xml.SelectSingleNode("//test-run.result").InnerText
    13.     - if ("Passed" -ne $result) { throw }
    14.   artifacts:
    15.     when: always
    16.     paths:
    17.       - unit-tests.xml
    18.     reports:
    19.       junit: unit-tests.xml
    20.   tags:
    21.     - unity
    22. unity-build:
    23.   stage: build
    24.   script: echo 'Building...'
    25.   tags:
    26.     - unity
    27. playstore:
    28.   stage: deploy
    29.   script: echo 'Deploying...'
    30.   tags:
    31.     - unity
    The ErrorActionPreference: Stop comes from here:; https://gitlab.com/gitlab-org/gitlab-runner/-/issues/3194
    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.
     
    DotusX likes this.
  4. davethemac

    davethemac

    Joined:
    Jan 8, 2020
    Posts:
    3
    12.
    - $result = $xml.SelectSingleNode('test-run').result
     
    DotusX likes this.