'Task AzureStaticWebApp@0 'could not detect this directory' but its presented

I am working on building a pipeline using AzureDevOps, and I face a strange problem.

This is my pipeline:

- stage: 'Test'
  displayName: 'Deploy to the test environment'
  dependsOn: Build
  jobs:
    - job: 'Deploy'
      steps:
      - download: current
        artifact: lorehub-front
      - bash: cd $(Pipeline.Workspace); echo $(ls)
      - bash: cd $(Pipeline.Workspace)/lorehub-front; echo $(ls)
      - task: AzureStaticWebApp@0
        displayName: 'Publish to Azure Static WebApp'
        inputs:
          app_location: $(Pipeline.Workspace)/lorehub-front
          azure_static_web_apps_api_token: xxxx

The first bash shows that the folder 'lorehub-front' is presented

The second bash shows that the inside folder is correct files (index.html and etc)

Script contents: cd /home/vsts/work/1/lorehub-front; echo $(ls)

android-chrome-192x192.png android-chrome-512x512.png apple-touch-icon.png css env-config.js favicon-16x16.png favicon-32x32.png favicon.ico fonts index.html js site.webmanifest

But I am receiving this error:

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



Solution 1:[1]

App Directory Location: '/home/vsts/work/1/lorehub-front' is invalid.

The method to resolve this issue is that you need to change the path to /lorehub-front.

  - task: AzureStaticWebApp@0
    displayName: 'Publish to Azure Static WebApp'
    inputs:
      app_location: /lorehub-front
      azure_static_web_apps_api_token: xxxx

For more detailed info, you could refer to this doc: Tutorial: Publish Azure Static Web Apps with Azure DevOps

Enter / if your application source code is at the root of the repository, or /app if your application code is in a directory called app.

Solution 2:[2]

In case anyone else comes across this post from Google or whatever, I had the exact same problem as Andrei above but for the life of me I couldn't get the accepted solution here to work.

No matter what I put in app_location:, the task just flat out refused to see any files.

Upon further investigation, I found this github issue which claims the following (Emphasis mine):

The AzureStaticWebApp task’s app location is relative to the current directory

Looking at the documentation, we can see that this task uses the default directory of $(System.DefaultWorkingDirectory), which is different to $(Pipeline.Workspace) for whatever reason.

So, if you find yourself stuck in the same position and cannot get this task to recognise your artifacts, the solution is to add cwd: $(Pipeline.Workspace) to your task, e.g.

strategy:
runOnce:
  deploy:
    steps:
      - download: current
        artifact: WebApp
      - task: AzureStaticWebApp@0
        inputs:
          app_location: /
          skip_app_build: true
          azure_static_web_apps_api_token: $(deployment_token)
          cwd: $(Pipeline.Workspace)/WebApp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kevin Lu-MSFT
Solution 2 Kushan