Tutorial: Deploy Bitbucket repositories on Azure Static Web Apps
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.
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.
Create a repository
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.
Select Import repository and wait a moment while the website creates your repository.
Set main branch
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.
Create a static web app
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.
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 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.
Create the pipeline task in Bitbucket
Go to the repository in Bitbucket.
Select the Source menu item.
Ensure the main branch is selected in the branch drop down.
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: - 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
In this example the value for
pipeis set to
mainwith 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.
$BITBUCKET_CLONE_DIRvariable maps to the repository's root folder location during the build process.
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 named
Location of your Azure Functions code. Enter
/apiif your api code is in a folder named
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 build as the
Next, define value for the
- 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.
View the website
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.
Clean up resources
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.
Submit and view feedback for