You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions windows-latest运行azure/cli@v2失败,提示需用Linux runner

解决GitHub Actions中windows-latest运行azure/cli@v2报错的问题

问题原因

azure/cli@v2官方Action的设计仅支持Linux-based runner,它依赖Linux容器来运行Azure CLI,未适配Windows环境,因此在windows-latest上执行时会触发"Please use Linux-based OS as a runner"的错误。

解决方案

方案1:直接在Windows runner上执行Azure CLI命令

windows-latest镜像默认已预装Azure CLI,无需依赖azure/cli@v2 Action,直接用run步骤执行命令即可:

- name: Copy file to Azure Storage 
  run: |
    az account show
    echo "github.workspace - " ${{ github.workspace }}
    az storage file upload --account-name 'winterazure' --account-key ${{ secrets.AZURE_STORAGE_KEY }} --share-name 'winterazure' --path 'drop/' --source "D:\a\Winter\Winter\Winter50\bin\Release\Winter50.dll"

注意:--path参数只需指定文件共享内的相对路径(如drop/),无需完整URL。

方案2:改用azure/cli@v1版本

azure/cli@v1支持Windows、Linux、macOS全平台,它会在runner上直接安装对应版本的Azure CLI,而非依赖容器:

- name: Copy file to Azure Storage 
  uses: azure/cli@v1
  with:
    azcliversion: latest
    inlineScript: |
      az account show
      echo "github.workspace - " ${{ github.workspace }}
      az storage file upload --account-name 'winterazure' --account-key ${{ secrets.AZURE_STORAGE_KEY }} --share-name 'winterazure' --path 'drop/' --source "D:\a\Winter\Winter\Winter50\bin\Release\Winter50.dll"

方案3:拆分作业为构建+上传两个阶段

若坚持使用azure/cli@v2,可将构建与上传拆分为独立作业:

  1. 第一阶段在windows-latest上完成构建,将DLL作为artifact上传;
  2. 第二阶段在ubuntu-latest上下载artifact,再用azure/cli@v2执行上传。

示例配置:

jobs:
  build:
    runs-on: windows-latest
    steps:
      # 保留原构建步骤(checkout、setup MSBuild、nuget还原、build)
      - name: Upload DLL artifact
        uses: actions/upload-artifact@v4
        with:
          name: winter50-dll
          path: Winter50/bin/Release/Winter50.dll

  upload-to-azure:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Download DLL artifact
        uses: actions/download-artifact@v4
        with:
          name: winter50-dll
      - name: Login to Azure
        uses: azure/login@v1
        env:
          CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
        with:
          creds: ${{ env.CREDENTIALS }}
      - name: Copy file to Azure Storage 
        uses: azure/cli@v2
        with:
          azcliversion: latest
          inlineScript: |
            az account show
            az storage file upload --account-name 'winterazure' --account-key ${{ secrets.AZURE_STORAGE_KEY }} --share-name 'winterazure' --path 'drop/' --source './Winter50.dll'

内容的提问来源于stack exchange,提问作者m_finn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 17:48:20