Gitlab-CI: set different variables/paths depending on specific runner

Viewed 897

I am using Gitlab CI to automate my unity builds. For this I use two machines. (one Mac and one windows machine. Important: build should only run on the first machine that is available. )

unity-build:
  script: "/Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/MacOS/Unity \      
  -projectPath pathXY \
  -executeMethod BuildScript.PerformBuild
  -quit"
  stage: build
  tags:
    - unity-mac-runner, unity windows runner

The problematic line is this: script: "/Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/MacOS/Unity, because on my windows runner path to unity is "S:\Unity\2019.3.14f1\Editor\Unity.exe" \

Tried to fix this with these changes:

windows job:
  stage: setpaths
  variables:
    UNITY_PATH: "S:/Unity/2019.3.14f1/Editor/Unity.exe"
  script: "set windows variables..."
  tags:
    - unity windows runner
#osx job:
#  stage: setpaths
#  variables:
#    UNITY_PATH: "S:/Unity/2019.3.14f1/Editor/Unity.exe"
#  script: "set mac variables..."
#  tags:
#    - unity-mac-runner

Questions

  1. How can I do this? What should I use?
  2. I tried to set path of unity installation depending on build runner, but I couldn't get this to work.

An example would be nice. Thx a lot ;)


Addition to the config.toml solution: I have this problem on Windows (Mac is running without problems.

     In C:\WINDOWS\TEMP\build_script782418789\script.ps1:185 Zeichen:15
 + ${UNITY_PATH} -batchmode -projectPath ${BUILD_PROJECT_PATH} -runTests ...
 +               ~~~~~~~~~~
 Unerwartetes Token "-batchmode" in Ausdruck oder Anweisung.
 In C:\WINDOWS\TEMP\build_script782418789\script.ps1:185 Zeichen:26
 + ${UNITY_PATH} -batchmode -projectPath ${BUILD_PROJECT_PATH} -runTests ...
 +                          ~~~~~~~~~~~~
 Unerwartetes Token "-projectPath" in Ausdruck oder Anweisung.
     + CategoryInfo          : ParserError: (:) [], ParseException
     + FullyQualifiedErrorId : UnexpectedToken
  
 ERROR: Job failed: exit status 1

Unexpected token ... in expression or statement.

This is my config.toml on windows:

  executor = "shell"
  shell = "powershell"
  environment = [
  "UNITY_PATH=S:/Unity/2019.4.1f1/Editor/Unity.exe",
  "BUILD_PROJECT_PATH=S:/Gitlab-runner/builds/QZ5_yEjt/0/FussballManager/Game",
  "UNITY_BUILD_PATH=S:/Gitlab-runner/builds/QZ5_yEjt/0/FussballManager/Game/WindowsBuild/"
  ]
1 Answers

One option is to split out the different macOS and Windows jobs, so something along the lines of:

build:mac:
  stage: build
  script:
    - "/Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/MacOS/Unity \      
        -projectPath pathXY \
        -executeMethod BuildScript.PerformBuild
        -quit"
  tags:
    - unity-mac-runner


build:windows:
  stage: build
  script:
    - "S:/Unity/2019.3.14f1/Editor/Unity.exe \      
        -projectPath pathXY \
        -executeMethod BuildScript.PerformBuild
        -quit"
  tags:
    - unity-windows-runner

You can also use templates/anchors if the script is very similar, eg:

.unity_template:
  stage: build
  script:
    - "${UNITY_PATH} -projectPath ${PROJECT_PATH} \
        -executeMethod BuildScript.PerformBuild
        -quit"

build:mac:
  extends: .unity_template
  variables:
    UNITY_PATH: "/Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/MacOS/Unity"
    PROJECT_PATH: "pathXY"
  tags:
    - unity-mac-runner

build:windows:
  extends: .unity_template
  variables:
    UNITY_PATH: "S:/Unity/2019.3.14f1/Editor/Unity.exe"
    PROJECT_PATH: "pathXY"
  tags:
    - unity-windows-runner

This would setup two jobs for the pipeline, and require that both runners are available.


Another option, is as you have mentioned, setting the path on the runner themselves. I'm not sure how you have it setup, but for example:

  • config.toml file for the mac:
[[runners]]
  ...
  environment = ["UNITY_PATH=/Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/MacOS/Unity"]
  ...
  • config.toml file for windows:
[[runners]]
  ...
  environment = ["UNITY_PATH=S:/Unity/2019.3.14f1/Editor/Unity.exe"]
  ...

and then in the CI file, it should be something similar to option one with:

unity_build:
  stage: build
  script:
    - "${UNITY_PATH} \      
        -projectPath pathXY \
        -executeMethod BuildScript.PerformBuild
        -quit"
  tags:
    - unity

See the advanced configuration for more information on editing the config.toml.

This would only setup one job for the pipeline, and use either of the unity runners available (ensure that both runners have the unity tag).

HTH!

Related