avatarJuarez Junior

Summary

This context provides a step-by-step guide on how to publish Azure Static Web Apps using Azure DevOps.

Abstract

The context begins by introducing Azure Static Web Apps, which publishes a website by building an app from a code repository. It then outlines the prerequisites for deploying an application to Azure Static Web Apps using Azure DevOps, including an active Azure account, an Azure DevOps project, and Azure Pipelines. The guide then proceeds to demonstrate how to create a static web app in an Azure DevOps project, import a sample application, and create a new static web app in the Azure portal. The final section of the guide covers creating a pipeline task in Azure DevOps to automate the deployment process.

Bullet points

  • Azure Static Web Apps publishes a website by building an app from a code repository.
  • Prerequisites for deploying an application to Azure Static Web Apps using Azure DevOps include an active Azure account, an Azure DevOps project, and Azure Pipelines.
  • The guide demonstrates how to create a static web app in an Azure DevOps project, import a sample application, and create a new static web app in the Azure portal.
  • The final section of the guide covers creating a pipeline task in Azure DevOps to automate the deployment process.

How to Publish Azure Static Web Apps with Azure DevOps

Azure Static Web Apps

by Juarez Junior

Azure Static Web Apps publishes a website by building an app from a code repository.

In this quick-start, you deploy an application to Azure Static Web apps using Azure DevOps.

Prerequisites

  • 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

Access Azure DevOps - https://azure.microsoft.com/en-us/pricing/details/devops/azure-devops-services/

On the right-hand side, under Basic Plan, click the Start Free button.

Azure DevOps -> Basic Plan -> Start free

Create your Azure DevOps organization. Click the Continue button.

Azure DevOps -> Create your org -> Continue

A progress indicator will appear and show that your DevOps organization is being created.

DevOps org — creation

Now, provide a name to your DevOps project, then click the Create project button.

DevOps project name -> Create project

Your project will be created, and you will see the home landing page on Azure DevOps and your respective project.

Azure DevOps -> project landing page

Navigate to your repository in Azure Repos. Select Import to begin importing a sample application. A Git repository type is selected by default.

In Clone URL, enter https://github.com/staticwebdev/vanilla-api.git.

Select Import.

Repos -> Files -> Import -> Git repo type -> Clone URL

You will see another progress indicator.

Importing GitHub repository

As soon as it finishes, you will see that your repository got imported successfully.

Repository imported successfully

Create a static web app

Navigate to the Azure portal.

Azure Portal — Create a resource

Select Create a Resource. Search for Static Web App.

Create a resource -> Static Web App

Select Static Web Apps. Select Create.

Static Web App -> Create

Create a new static web app with the values specific to your Azure subscription and your preferred parameter arguments.

Note that you can use an existing Resource Group or create a new one.

Subscription: Your Azure subscription name.

Resource Group: Select an existing group name, or create a new one.

Name: Enter myDevOpsApp.

Hosting plan, Plan type: Select Free.

Region: Select a region closest to you.

Source: Select Other.

Click the Review + create button.

Create SWA — values

Select Create.

Create Static Web App

The SWA deployment will start.

SWA — deployment i n progress

As soon as it completes, you will see a confirmation message as well. Then, click the Go to resource button.

SWA -> deployment complete -> Go to resource

Select Manage deployment token.

SWA -> Manage deployment token

Copy the deployment token and paste the deployment token value into a text editor for use on another screen. Click the Close button.

Deployment token

Create the Pipeline Task in Azure DevOps

Navigate to the repository in Azure Repos that was created earlier.

Select Set up build.

Set up build

In the Configure your pipeline screen, select Starter pipeline.

Pipeline -> Starter Pipeline

Copy the following YAML and replace the generated configuration in your pipeline with the code below.

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)
Review your pipeline YAML

Select Variables.

Variables

Select New variable.

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 OK.

deployment_token -> your token value -> OK

Select Save to return to your pipeline YAML.

Save

Select Save and run to open the Save and run dialog.

Save and run

Select Save and run to run the pipeline.

Save and run

You will see an indicator message concerning the pipeline creation.

Creating 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.

SWA — URL

Clean up resources

Clean up the resources you deployed by deleting the resource group.

From the Azure portal, select Resource group.

Resource groups

Select the respective resource group name you used in this tutorial.

Resource groups -> devopsjsconfrg

Select Delete resource group from the top menu.

Delete resource group

Confirm the resource group deletion operation by providing the target resource group name. Click the Delete button.

Resource group -> Delete

That’s it. You created your first Azure Static Web Apps, and built and deployed it with Azure DevOps! Congratulations!

If you want to learn more about Azure Static Web Apps, please check the resources below.

Azure Static Web Apps — Streamlined full-stack development from source code to global high availability

Azure Static Web Apps — Documentation

Azure Static Web Apps — Free courses @ Microsoft Learn

Azure
Azure Devops
Swa
Github
Azure Pipelines
Recommended from ReadMedium