【问题标题】:Gitlab-CI: set different variables/paths depending on specific runnerGitlab-CI:根据特定的跑步者设置不同的变量/路径
【发布时间】:2020-06-27 23:04:26
【问题描述】:

我正在使用 Gitlab CI 来自动化我的统一构建。为此,我使用两台机器。 (一台 Mac 和一台 windows 机器。重要提示:构建应该只在第一台可用的机器上运行。)

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

有问题的行是:脚本:“/Applications/Unity/Hub/Editor/2019.3.14f1/Unity.app/Contents/MacOS/Unity,因为在我的 Windows 运行器上,统一路径是“S:\Unity\ 2019.3.14f1\Editor\Unity.exe" \

尝试通过以下更改来解决此问题:

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

问题

  1. 我该怎么做?我应该使用什么?
  2. 我尝试根据构建运行器设置统一安装路径,但无法正常工作。

举个例子就好了。非常感谢 ;)


对 config.toml 解决方案的补充:我在 Windows 上遇到了这个问题(Mac 运行时没有问题。

     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

表达式或语句中出现意外的标记...。

这是我在 Windows 上的 config.toml:

  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/"
  ]

【问题讨论】:

    标签: unity3d continuous-integration gitlab gitlab-ci gitlab-ci-runner


    【解决方案1】:

    一种选择是将不同的 macOS 和 Windows 作业分开,因此类似于:

    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
    

    如果脚本非常相似,您也可以使用模板/锚点,例如:

    .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
    

    这将为管道设置两个作业,并要求两个运行器都可用。


    另一个选项,正如您所提到的,在跑步者自己上设置路径。我不确定您是如何设置的,但例如:

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

    然后在 CI 文件中,它应该类似于选项一:

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

    有关编辑config.toml 的更多信息,请参阅advanced configuration

    这只会为管道设置一个作业,并使用任何一个可用的统一运行器(确保两个运行器都有 unity 标签)。

    HTH!

    【讨论】:

    • 感谢您的帮助。我首先尝试了您的第二个解决方案: .unity_template: 但在我的 gitlab CI/CD 页面上,此提交被标记为卡住。如果我单击未完成的构建阶段,我可以看到我的 mac 运行器已完成,但我正在等待我的 windows 运行器(现在处于脱机状态)。如果其中一项工作成功,有没有办法让这个构建进入下一阶段? (我不需要同时使用 windows runner 和 mac。)
    • 第一个选项(和模板选项)要求两个运行器都可用。我已经更新了为两个跑步者更新 config.toml 的第三个选项,请告诉我它是如何工作的?
    • 如果我使用这个:标签:- unity-mac-runner - unity-windows-runner。我想它也会尝试在两台机器上运行?
    • 啊,gitlab 会尝试找一台有这两个标签的机器。您可能希望为两台机器分配另一个标签,例如unity。我又更新了答案。
    • 我将在下周末工作(我目前正在休假,无法访问我的 windows 计算机)。我会把奖赏给你,但我会等待接受这个答案。 (看来您的解决方案是正确的,但我们现在缺少一些奇怪的窗口设置;))
    猜你喜欢
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 2019-08-07
    • 2021-08-10
    • 2023-03-15
    • 1970-01-01
    • 2021-12-12
    • 2017-12-29
    相关资源
    最近更新 更多