Tutorial: Publish Azure Static Web Apps with Azure DevOps
In this tutorial, you learn to:
- Set up an Azure Static Web Apps site
- Create an Azure Pipeline to build and publish a static web app
- Active Azure account: If you don't have one, you can create an account for free.
- Azure DevOps project: If you don't have one, you can create a project for free.
- Azure DevOps includes Azure Pipelines. If you need help getting started with Azure Pipelines, see Create your first pipeline.
- The Static Web App Pipeline Task currently only works on Linux machines. When running the pipeline mentioned below, please ensure it is running on a Linux VM.
Create a static web app in an Azure DevOps
If you have an existing app in your repository, you may skip to the next section.
Navigate to your repository in Azure Repos.
Select Import to begin importing a sample application.
In Clone URL, enter
Create a static web app
Navigate to the Azure portal.
Select Create a Resource.
Search for Static Web Apps.
Select Static Web Apps.
Create a new static web app with the following values.
Setting Value Subscription Your Azure subscription name. Resource Group Select an existing group name, or create a new one. Name Enter myDevOpsApp. Hosting plan type Select Free. Region Select a region closest to you. Source Select Other.
Select Review + create
Once the deployment is successful, select Go to resource.
Select Manage deployment token.
Copy the deployment token and paste the deployment token value into a text editor for use in another screen.
This value is set aside for now because you'll copy and paste more values in coming steps.
Create the Pipeline Task in Azure DevOps
Navigate to the repository in Azure Repos that was created earlier.
Select Set up build.
In the Configure your pipeline screen, select Starter pipeline.
Copy the following YAML and replace the generated configuration in your pipeline with this code.
trigger: - main pool: vmImage: ubuntu-latest steps: - checkout: self submodules: true - task: AzureStaticWebApp@0 inputs: app_location: '/src' api_location: 'api' output_location: '/src' azure_static_web_apps_api_token: $(deployment_token)
If you are not using the sample app, the values for
output_locationneed to change to match the values in your application.
Property Description Example Required
Location of your application code. Enter
/if your application source code is at the root of the repository, or
/appif your application code is in a directory called
Location of your Azure Functions code. Enter
/apiif your app code is in a folder called
api. If no Azure Functions app is detected in the folder, the build doesn't fail, the workflow assumes you don't want an API.
Location of the build output directory relative to the
If your application source code is located at
/app, and the build script outputs files to the
/app/buildfolder, then set
azure_static_web_apps_api_tokenvalue is self managed and is manually configured.
Select New variable.
Name the variable deployment_token (matching the name in the workflow).
Copy the deployment token that you previously pasted into a text editor.
Paste in the deployment token in the Value box.
Select Keep this value secret.
Select Save to return to your pipeline YAML.
Select Save and run to open the Save and run dialog.
Select Save and run to run the pipeline.
Once the deployment is successful, navigate to the Azure Static Web Apps Overview which includes links to the deployment configuration. Note how the Source link now points to the branch and location of the Azure DevOps repository.
Select the URL to see your newly deployed website.
Clean up resources
Clean up the resources you deployed by deleting the resource group.
- From the Azure portal, select Resource group from the left menu.
- Enter the resource group name in the Filter by name field.
- Select the resource group name you used in this tutorial.
- Select Delete resource group from the top menu.