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

GitHub CI流水线持续失败:az cli脚本执行出错求助

GitHub CI流水线持续失败:az cli script failed 报错排查

我配置的GitHub CI流水线一直失败,报错信息如下:

Error: az cli script failed. UnhandledPromiseRejectionWarning: Error: az cli script failed.

我的流水线配置代码如下:

env:
  AZURE_WEBAPP_PACKAGE_PATH: '.'     
  DOTNET_VERSION: '6.0.x'           

on:
 
  push:
    branches: master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Set up .NET Core
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: ${{ env.DOTNET_VERSION }}

      - name: Set up dependency caching for faster builds
        uses: actions/cache@v2
        with:
          path: ~/.nuget/packages
          key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
          restore-keys: |
            ${{ runner.os }}-nuget-

      - name: Build with dotnet
        run: dotnet build --configuration Release

      - name: Test
        run: dotnet test --no-restore --verbosity normal

      - name: dotnet publish
        run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
        with:
          name: .net-app
          path: ${{env.DOTNET_ROOT}}/myapp

      - name: Login to Aure
        uses: azure/login@v1
        with:
            creds: ${{ secrets.AZURE_CREDENTIALS }}
            
  deploy:
        runs-on: ubuntu-latest
        needs: build
        environment:
          name: 'development'
          url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

        steps:
          - name: Download artifact from build job
            uses: actions/download-artifact@v3
            with:
              name: .net-app
            
          - name: Deploy to Azure
            uses: azure/CLI@v1
            with:
              azcliversion: latest
              inlineScript: |
                az deployment group create \
                -- name \
                -- resource-group  \
                -- template-file Template/template.json \
                -- parameters storageAccountType=Standard_LRS 

报错原因及修复方案

  • CLI命令参数缺失:az deployment group create里的--name和--resource-group后面没有填写具体值,这是CLI执行失败的核心原因。必须补充你的部署名称和目标资源组名称。
  • 登录上下文不共享:Login to Azure步骤放在build job中,但deploy job是独立运行的,无法继承build的登录状态。需要把登录步骤移到deploy job内,确保部署时拥有有效Azure认证。
  • 拼写错误:Login to Aure中的Aure是笔误,应为Azure,建议修正避免混淆。
  • 环境URL引用错误:deploy job的url引用了steps.deploy-to-webapp.outputs.webapp-url,但你的部署步骤名称是Deploy to Azure,没有匹配的ID,会导致变量引用失败。需给部署步骤添加id并对应修改引用。

修正后的关键代码示例

  1. 调整deploy job的登录和部署命令:
deploy:
  runs-on: ubuntu-latest
  needs: build
  environment:
    name: 'development'
    url: ${{ steps.azure-deploy.outputs.webapp-url }} # 匹配步骤ID

  steps:
    - name: Download artifact from build job
      uses: actions/download-artifact@v3
      with:
        name: .net-app
    
    - name: Login to Azure
      uses: azure/login@v1
      with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
    
    - name: Deploy to Azure
      id: azure-deploy # 添加ID用于环境URL引用
      uses: azure/CLI@v1
      with:
        azcliversion: latest
        inlineScript: |
          az deployment group create \
          --name my-deployment-name \ # 替换为你的部署名称
          --resource-group my-target-resource-group \ # 替换为你的资源组名称
          --template-file Template/template.json \
          --parameters storageAccountType=Standard_LRS 
  1. 修正build job中的拼写错误:
- name: Login to Azure
  uses: azure/login@v1
  with:
      creds: ${{ secrets.AZURE_CREDENTIALS }}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 16:51:33