尝试使用 Microsoft 托管代理“windows-latest”或“windows-2019”在 Azure DevOps 中构建以下 Docker 映像时出现以下错误
Docker 文件内容是
# escape=`
FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
# Install Powershell
RUN powershell -Command "Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine"
# Install Nuget package provider
RUN powershell -Command "Install-PackageProvider -Name NuGet -Force -Scope AllUsers"
WORKDIR /azp/
COPY ./start.ps1 ./
CMD powershell .\start.ps1
Devops 管道 YAML
pool:
vmImage: windows-2019
stages:
- stage: Build
jobs:
- job: BuildWindows
steps:
- task: AzureCLI@2
inputs:
azureSubscription: 'XXXXXX'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: az acr build --image devops/windows:latest --registry registryName --no-push .
workingDirectory: '$(System.DefaultWorkingDirectory)/images/windows'
是否尝试将代理从“windows-latest”更改为“windows-2019”,但没有帮助
此外,经过进一步研究发现,Windows-latest 或任何 Windows Agent 默认情况下都使用 Linux 容器。那么有没有办法在微软托管代理中将容器切换到windows呢?
使用 az acr build 命令构建 Windows 映像时,我可以重现相同的问题。
默认情况下,该命令将使用 Linux 操作系统来构建 docker 镜像。
要解决此问题,您需要将
--platform windows
参数添加到 az acr build 命令中。
例如:
az acr build --image devops/windows:latest --registry xx --platform windows --no-push .
Yaml 示例:
pool:
vmImage: windows-2019
stages:
- stage: Build
jobs:
- job: BuildWindows
steps:
- task: AzureCLI@2
inputs:
azureSubscription: 'XXXXXX'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: az acr build --image devops/windows:latest --registry xx --platform windows --no-push .
workingDirectory: '$(System.DefaultWorkingDirectory)/images/windows'
更详细的信息,您可以参考文档:az acr build