Azure DevOps 2019 – 添加脚本导致构建代理的更改

huangapple go评论68阅读模式
英文:

Azure DevOps 2019 - Adding Script leads to change of the building agent

问题

今天我不得不将我的构建代理从VS2019切换到VS2022,因为发现DevOps 2019的MSBuild任务版本与VS2022不兼容。

所以我找到了一个解决方法。这个解决方法是使用以下“script”而不是“MSBuild”任务。但是使用这个“script”时,我遇到了以下的问题:

  1. 如果我使用“MSBuild@1”任务,我的流水线会因为上述兼容性问题而崩溃。但是流水线使用了正确的构建代理。
  2. 如果我使用“Script”,流水线会崩溃,因为它使用了错误的构建代理。这个代理没有安装Unity,并且在YAML中也没有提到。

YAML:

  - task: MSBuild@1
    displayName: 'Build Appx Package - MSBuild@1'
    inputs:
      solution: '$(Build.BinariesDirectory)$(unity.outputPath)/*.sln'
      msbuildVersion: 'latest'
      platform: 'ARM64'
      configuration: 'Release'
      msbuildArguments: '/p:AppxBundle=Always /p:AppxPackageDir=$(Build.ArtifactStagingDirectory)/AppPackages'
  # ----- or ------
  - script: |
      @echo off
      setlocal enabledelayedexpansion
      for /f "usebackq tokens=*" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe') do (set msbuild_exe=%%i)
      "!msbuild_exe!" "$(Build.BinariesDirectory)$(unity.outputPath)/*.sln" /p:Configuration=Release /p:Platform="ARM64" /p:AppxBundle=Always /p:AppxPackageDir=$(Build.ArtifactStagingDirectory)/AppPackages /t:rebuild      

在我的YAML文件开头,我当然设置了池和构建代理的名称:

- job: unity
  pool:
    name: 'My_Pool'
    demand: Agent.name -equals My_Agent_Unity_1

我不明白为什么移除MSBuild任务并添加script会导致突然使用不同的构建代理。

英文:

I have a local building agent for a Unity|HoloLens-Project. Today I had to switch from VS2019 to VS2022 on my building agent and I came across the issue, that the MSBuild-Task-Version of DevOps 2019 is not compatible with VS2022.

So I found a workaround. That workaround is to use the following script instead of the MSBuild task. But using that script I ran into the following misbehavior:
<br>

  1. If I use the MSBuild@1-task my pipeline crashes because of mentioned compatibility problem. But the pipeline uses the right building agent.
  2. If I use the Script the pipeline crashes because it uses the wrong building agent. That agent has no unity installed and is not mentioned in the YAML.

<br>
Yaml:

  - task: MSBuild@1
    displayName: &#39;Build Appx Package - MSBuild@1&#39;
    inputs:
      solution: &#39;$(Build.BinariesDirectory)$(unity.outputPath)/*.sln&#39;
      msbuildVersion: &#39;latest&#39;
      platform: &#39;ARM64&#39;
      configuration: &#39;Release&#39;
      msbuildArguments: &#39;/p:AppxBundle=Always /p:AppxPackageDir=$(Build.ArtifactStagingDirectory)/AppPackages&#39;
  # ----- or ------
  - script: |
      @echo off
      setlocal enabledelayedexpansion
      for /f &quot;usebackq tokens=*&quot; %%i in (`&quot;!ProgramFiles(x86)!\Microsoft Visual Studio\Installer\vswhere.exe&quot; -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) do (set msbuild_exe=%%i)
      &quot;!msbuild_exe!&quot; &quot;$(Build.BinariesDirectory)$(unity.outputPath)/*.sln&quot; /p:Configuration=Release /p:Platform=&quot;ARM64&quot; /p:AppxBundle=Always /p:AppxPackageDir=$(Build.ArtifactStagingDirectory)/AppPackages /t:rebuild

At the beginng of my YAML I set of course the pool and the name of the building agent:
<br>

- job: unity
  pool:
    name: &#39;My_Pool&#39;
    demand: Agent.name -equals My_Agent_Unity_1

I don't understand how removing the MSBuild task and adding the script can cause a different building agent to suddenly be taken.

答案1

得分: 1

因为您在您的YAML中输入了错误的关键字“demand”,应该是demands

- job: unity
  pool:
    name: 'My_Pool'
    demands: Agent.name -equals My_Agent_Unity_1

请参阅手动输入的要求池定义以获取详细信息。

英文:

> I don't understand how removing the MSBuild task and adding the script
> can cause a different building agent to suddenly be taken.

Because you entered the wrong keyword "demand" in your YAML. It should be demands.

- job: unity
  pool:
    name: &#39;My_Pool&#39;
    demands: Agent.name -equals My_Agent_Unity_1

Please see Manually entered demands and pool definition for details.

huangapple
  • 本文由 发表于 2023年1月9日 19:04:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056351.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定