I am trying to deploy my first Azure Static Web App from Azure DevOps using a self-hosted agent on my local Windows machine. The agent is set up and appears online in the Azure DevOps settings. However, I am encountering an issue with the AzureStaticWebApp
task in my pipeline.
Here is the YAML configuration of the pipeline:
name: Azure Static Web Apps CI/CD
pr:
branches:
include:
- master
trigger:
branches:
include:
- master
jobs:
- job: build_and_deploy_job
displayName: Build and Deploy Job
condition: or(eq(variables['Build.Reason'], 'Manual'),or(eq(variables['Build.Reason'], 'PullRequest'),eq(variables['Build.Reason'], 'IndividualCI')))
pool:
name: Local Agent Pool
variables:
- group: Azure-Static-Web-Apps-victorious-beach-0d42cb803-variable-group
steps:
- checkout: self
submodules: true
- task: AzureStaticWebApp@0
inputs:
azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN_VICTORIOUS_BEACH_0D42CB803)
app_location: "/"
api_location: ""
output_location: "build"
skip_api_build: true
Now the issue: When I run the pipeline, the AzureStaticWebApp task fails with the following error message:
2024-10-04T14:42:16.5040695Z [command]C:WINDOWSsystem32bash.exe C:agent_work_tasksAzureStaticWebApp_18aad896-e191-4720-88d6-8ced4806941a.246.1launch-docker.sh
2024-10-04T14:42:22.3067301Z /bin/bash: C:agent_work_tasksAzureStaticWebApp_18aad896-e191-4720-88d6-8ced4806941a0.246.1launch-docker.sh: No such file or directory
2024-10-04T14:42:22.3142262Z
2024-10-04T14:42:22.3238448Z ##[error]Error: The process 'C:WINDOWSsystem32bash.exe' failed with exit code 127
2024-10-04T14:42:22.3285032Z ##[section]Finishing: AzureStaticWebApp
I think the problem appears to be related to how paths are being handled. The command that fails seems to use a Windows-style path, but the Bash environment expects a Linux-style path. I believe it should look something like this:
C:WINDOWSsystem32bash.exe mntcagent_work_tasksAzureStaticWebApp_18aad896-e191-4720-88d6-8ced4806941a.246.1launch-docker.sh
But I have no idea to change it, nor any idea if I should change it somewhere or if my configuration is incorrect… Any help?
WSL is correctly installed and docker is also accessible within the WSL environment.
2
Answers
The AzureStaticWebApp@0 task can only run on Linux agents. It is not available for Windows agents.
To run this task, you can:
Use the Microsoft-hosted agents which is on Linux VM, such as
ubuntu-24.04
,ubuntu-22.04
(ubuntu-latest
) orubuntu-20.04
.Install self-hosted agents on yourself local Linux machines or Linux VM.
The correct answer is already given by Bright Ran-MSFT. I only want to say that you can use a workaround if you don’t want to make use of an Linux agent.
You can also make use of a storage account for static websites. I am not sure if that will fit your needs, but if it does, than you might consider to use the option below.
How I deploy a static website is:
I am using an ARM template for a storage account.
The second task is a AzurePowershell task which I use to enable static website.
Maybe this will help you to deploy it as an workaround. I have not included the arm template and the script itself, but if you need I can paste it here.