Search code examples
azure-devopspipelineazure-static-web-app

Could not detect this directory


I have an application in react, and I have to build and deploy it in the Static Web App... But I'm facing a problem.

The problem:

Deploying project to Azure Static Web Apps...
Could not find StaticSitesClient local binary
- Downloading https://swalocaldeploy.azureedge.net/downloads/1.0.026911/linux/[email protected]
[swa] ✔ Downloading https://swalocaldeploy.azureedge.net/downloads/1.0.026911/linux/[email protected]
- Preparing deployment. Please wait...
✖App Directory Location: '/home/vsts/work/1/a/####.zip' is invalid. Could not detect this directory. Please verify your deployment configuration file reflects your repository structure.

The part of the code that is causing the problem:

    - task: Bash@3
      inputs:
        targetType: inline
        script: |
          npm install -g @azure/static-web-apps-cli
          swa deploy $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip --app-name $(STATIC_WEB_APP_NAME) --resource-group $(TFSTATE_RESOURCE_GROUP_NAME) --deployment-token $(STATICWEBAPP_DEPLOYMENT_TOKEN)
      displayName: 'Deploy to Azure Static Web App'

code where I created it I create the artifact:

    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: '$(Build.SourcesDirectory)/FrontEnd/dist'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true
      displayName: 'Archive files'

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'staticAppArtifact'
      displayName: 'Publish Artifact'

Can you help me?

I tried several ways to solve it without success


Solution

  • I can reproduce the same issue when using the swa cli to deploy the Azure Static Web App.

    enter image description here

    The cause of the issue is that the command doesn't support deploying zip packages to Azure Static Web App.

    To solve this issue, you can directly define the dist folder path in the swa deploy command.

    For example:

     swa deploy $(Build.SourcesDirectory)/FrontEnd/dist/  --app-name $(STATIC_WEB_APP_NAME) --resource-group $(TFSTATE_RESOURCE_GROUP_NAME) --deployment-token $(STATICWEBAPP_DEPLOYMENT_TOKEN)
    

    For more detailed info, you can refer to this doc: Deploy a static web app with Azure Static Web Apps CLI