You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Azure Static Web Apps关闭PR任务报错:未找到匹配静态站点

解决Azure Static Web Apps关闭PR预览环境时的“No matching static site found”错误

问题根源

关闭PR的任务缺少必要的身份验证和上下文参数,导致Azure无法关联到对应的预览环境。你的close_pull_request任务仅传入了API令牌和action类型,没有提供匹配预览站点所需的GitHub仓库令牌、OIDC身份令牌,以及与构建任务一致的应用配置参数。

修复步骤

1. 完善Close Pull Request任务的参数与步骤

修改close_pull_request任务,添加身份验证步骤并补充必要参数,确保Azure能正确识别要删除的预览环境:

close_pull_request:
  if: github.event_name == 'pull_request' && github.event.action == 'closed'
  runs-on: ubuntu-latest
  name: Close Pull Request
  steps:
    - name: Setup Node.js for Yarn
      uses: actions/setup-node@v4
      with:
        cache: 'yarn'
        node-version-file: '.nvmrc'
    - name: Install OIDC Dependencies
      run: yarn add @actions/core@1.6.0 @actions/http-client
    - name: Get Id Token
      uses: actions/github-script@v6
      id: idtoken
      with:
        script: |
          const core = require('@actions/core')
          return await core.getIDToken()
        result-encoding: string
    - name: Close Pull Request
      id: closepullrequest
      uses: Azure/static-web-apps-deploy@v1
      with:
        azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_xxx }}
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        action: 'close'
        app_location: '/' # 与build任务保持一致
        api_location: '' # 与build任务保持一致
        output_location: '<my-output-location>' # 与build任务保持一致
        github_id_token: ${{ steps.idtoken.outputs.result }}

2. 关键参数说明

  • repo_token:提供GitHub仓库的上下文信息,帮助Azure定位PR对应的预览环境
  • github_id_token:通过OIDC验证身份,确保请求有权限操作对应的静态站点
  • 保持app_locationapi_locationoutput_location与构建任务一致:避免因配置不匹配导致环境识别失败

3. 额外检查点

  • 确认Azure Static Web Apps的OIDC配置已正确启用:在Azure门户的静态Web应用设置中,检查身份验证提供商是否包含GitHub,且权限配置正确
  • 验证GitHub仓库的id-token: write权限已生效:你的工作流中permissions部分已配置该权限,无需修改

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

火山引擎 最新活动