Search code examples
azure-devopsazure-pipelines

AzureStaticWebApp@0 push from artifacts


I've a CD pipeline that builds a project (multiple times for different environments) and publishes / saves the ./dist directories as one stage. I can download each environment and run locally as expected.

Each environment build is a stage that needs a manual approval. This is where I am getting lost. Each stage shows the correct artifact being pulled into the stage BUT the AzureStaticWebApp@0 -> app_location input results in a "Could not detect this directory." error.

To recap: After building the project and saving as an artifact (I can manually download and verify) I am unable to push that built code to Azure Static Web App as it cannot be found. I've tried any number of combinations to no effect. Any advice?

I'm using templates, here is the Push Built Project to Azure Static Web Apps template

When this template runs, I can see jobs running and successfully pulling down the right artifact with this output:

Successfully downloaded artifacts to /home/vsts/work/1/
Finishing: Download Artifact

But the AzureStaticWebApp@0 task gives this error:

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.

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)

EDIT

Does the task AzureStaticWebApp not have access to anything outside the project?

 - 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)


Solution

  • Solved --- well found a way to make it work.

    1. The build step created 'app/dist' directory and content
    2. The 'app/dist' folder only is published as an artifact
    3. When downloading the artifact you need to 'put it back' into the project. In this case 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)