Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure Static Web Apps has flexible deployment options that allow to work with various providers. In this tutorial, you deploy a web application hosted in Bitbucket to Azure Static Web Apps using a Linux virtual machine.
Note
The Static Web Apps pipeline task currently only works on Linux machines.
In this tutorial, you learn to:
- Import a repository to Bitbucket
- Create a static web app
- Configure the Bitbucket repo to deploy to Azure Static Web Apps
- Bitbucket account
- Ensure you have enabled two-step verification
- Azure account
- If you don't have an Azure subscription, create a free trial account.
This article uses a GitHub repository as the source to import code into a Bitbucket repository.
Sign in to Bitbucket.
Go to https://bitbucket.org/repo/import to begin the import process.
Under the Old repository label, in the URL box, enter the repository URL for your choice of framework.
Next to the Project label, select Create new project.
Enter MyStaticWebApp.
Select Import repository and wait a moment while the website creates your repository.
From time to time the template repository have more than one branch. Use the following steps to ensure Bitbucket maps the main tag to the main branch in the repository.
- Select Repository settings.
- Expand the Advanced section.
- Under the Main branch label, ensure main is selected in the drop down.
- If you made a change, select Save changes.
- Select Back.
Now that the repository is created, you can create a static web app from the Azure portal.
Go to the Azure portal.
Select Create a Resource.
Search for Static Web Apps.
Select Static Web Apps.
Select Create.
In the Basics section, begin by configuring your new app.
Setting Value Azure subscription Select your Azure subscription. Resource Group Select the Create new link and enter static-web-apps-bitbucket. Name Enter my-first-static-web-app. Plan type Select Free. Region for Azure Functions API and staging environments Select the region closest to you. Source Select Other. Select Review + create.
Select Create.
Select Go to resource.
Select Manage deployment token.
Copy the deployment token value and set it aside in an editor for later use.
Select Close on the Manage deployment token window.
Go to the repository in Bitbucket.
Select the Source menu item.
Ensure the main branch is selected in the branch drop down.
Select Pipelines.
Select text link Create your first pipeline.
On the Starter pipeline card, select Select.
Enter the following YAML into the configuration file.
pipelines: branches: main: - step: name: Deploy to test deployment: test script: - chown -R 165536:165536 $BITBUCKET_CLONE_DIR - pipe: microsoft/azure-static-web-apps-deploy:main variables: APP_LOCATION: '$BITBUCKET_CLONE_DIR/src' OUTPUT_LOCATION: '$BITBUCKET_CLONE_DIR/src' API_TOKEN: $deployment_token
Note
In this example the value for
pipe
is set tomicrosoft/azure-static-web-apps-deploy:main
. Replacemain
with your desired branch name if you want your pipeline to work with a different branch.The following configuration properties are used in the configuration file for your static web app.
The
$BITBUCKET_CLONE_DIR
variable maps to the repository's root folder location during the build process.Property Description Example Required app_location
Location of your application code. Enter /
if your application source code is at the root of the repository, or/app
if your application code is in a directory namedapp
.Yes api_location
Location of your Azure Functions code. Enter /api
if your api code is in a folder namedapi
. If no Azure Functions app is detected in the folder, the build doesn't fail, the workflow assumes you don't want an API.No output_location
Location of the build output directory relative to the app_location
.If your application source code is located at /app
, and the build script outputs files to the/app/build
folder, then setbuild
as theoutput_location
value.No
Next, define value for the API_TOKEN
variable.
- Select Add variables.
- In the Name box, enter deployment_token, which matches the name in the workflow.
- In the Value box, paste in the deployment token value you set aside in a previous step.
- Check the Secured checkbox.
- Select Add.
- Select Commit file and return to your pipelines tab.
Wait a moment on the Pipelines window and you'll see your deployment status appear. Once the deployment is finished running, you can view the website in your browser.
There are two aspects to deploying a static app. The first step creates the underlying Azure resources that make up your app. The second is a Bitbucket workflow that builds and publishes your application.
Before you can go to your new static site, the deployment build must first finish running.
The Static Web Apps overview window displays a series of links that help you interact with your web app.
- Return to your static web app in the Azure portal.
- Go to the Overview window.
- Select the link under the URL label. Your website loads in a new tab.
If you're not going to continue to use this application, you can delete the Azure Static Web Apps instance and all the associated services by removing the resource group.
- Select the static-web-apps-bitbucket resource group from the Overview section.
- Select Delete resource group at the top of the resource group Overview.
- Enter the resource group name static-web-apps-bitbucket in the Are you sure you want to delete "static-web-apps-bitbucket"? confirmation dialog.
- Select Delete.
The process to delete the resource group may take a few minutes to complete.