AzureStaticWebApp@0 来自项目的推送

use*_*684 4 azure-devops azure-pipelines

我有一个 CD 管道,可以构建一个项目(针对不同的环境多次)并将目录发布/保存./dist为一个阶段。我可以下载每个环境并按预期在本地运行。

每个环境构建都是一个需要手动批准的阶段。这就是我迷路的地方。每个阶段都会显示正确的工件被拉入该阶段,但结果AzureStaticWebApp@0 -> app_location input是“无法检测到此目录”。错误。

回顾一下:构建项目并保存为工件(我可以手动下载和验证)后,我无法将该构建的代码推送到 Azure Static Web App,因为找不到它。我尝试了多种组合都没有效果。有什么建议吗?

我正在使用模板,这里是将构建项目推送到 Azure Static Web Apps 模板

当此模板运行时,我可以看到作业正在运行,并通过以下输出成功拉取正确的工件:

Successfully downloaded artifacts to /home/vsts/work/1/
Finishing: Download Artifact
Run Code Online (Sandbox Code Playgroud)

AzureStaticWebApp@0任务给出了这个错误:

App Directory Location: '/home/vsts/work/1/DEV' is invalid. Could not detect this directory. Please verify your deployment configuration file reflects your repository structure.

Run Code Online (Sandbox Code Playgroud)
parameters:
  - name: environment
    default: development
    type: string
  - name: variableGroup
    default: development-variables-group
    type: string

jobs:
  - deployment: 
    displayName: 'Deploy to'
    environment: ${{parameters.environment}}
    variables:
      - group: ${{parameters.variableGroup}}
    pool:
      vmImage: ubuntu-latest
    strategy:
      runOnce:
        deploy:
          steps:
            - task: AzureStaticWebApp@0
              inputs:
                app_location: '$(Pipeline.Workspace)/DEV'
                api_location: 'api'
                output_location: 'dist'
                skip_app_build: true
              env:
                azure_static_web_apps_api_token: $(deployment-token)
Run Code Online (Sandbox Code Playgroud)

编辑

任务 AzureStaticWebApp 是否无权访问项目外部的任何内容?

 - deployment: 
    displayName: 'Deploy to'
    environment: ${{parameters.environment}}
    variables:
      - group: ${{parameters.variableGroup}}
    pool:
      vmImage: ubuntu-latest
    strategy:
      runOnce:
        deploy:
          steps:
            - checkout: self
              submodules: true
            # This step pulls down a complied site. E.g DEV/index.htm, ./images, staticwebapp.config.json
            # That has an output like:
            # Downloading DEV/index.html to /home/vsts/work/1/DEV/index.html
            # Successfully downloaded artifacts to /home/vsts/work/1/
            - download: current
              artifact: DEV
            - task: AzureStaticWebApp@0
              inputs:
              # I've tried many different values for app_location but all return back not found error
                app_location: '/DEV'
                api_location: 'api'
                output_location: 'dist'
                skip_app_build: true
              env:
                azure_static_web_apps_api_token: $(deploymenttoken)

Run Code Online (Sandbox Code Playgroud)

use*_*684 7

解决了——很好地找到了让它发挥作用的方法。

  1. 构建步骤创建了“app/dist”目录和内容
  2. “app/dist”文件夹仅作为工件发布
  3. 下载工件时,您需要将其“放回”项目中。在本例中 DEV/ -> app/dist。
 - task: DownloadPipelineArtifact@2
              inputs:
                artifact: DEV
                path: ./app/dist # Put build artifact back into the project
                displayName: "Download artifacts"
            - task: AzureStaticWebApp@0
              inputs:
                app_location: 'app/dist'
                api_location: 'api'
                output_location: 'dist'
                skip_app_build: true
              env:
                azure_static_web_apps_api_token: $(deploymenttoken)
Run Code Online (Sandbox Code Playgroud)