Tutorial: Deploy GitLab repositories on Azure Static Web Apps
Azure Static Web Apps has flexible deployment options that allow to work with various providers. In this article, you deploy a web application hosted in GitLab to Azure Static Web Apps.
In this tutorial, you learn to:
- Import a repository to GitLab
- Create a static web app
- Configure the GitLab repo to deploy to Azure Static Web Apps
Create a repository
This article uses a GitHub repository as the source to import code into a GitLab repository.
Sign in to your GitLab account and navigate to https://gitlab.com/projects/new#import_project
Select the Repo by URL button.
In the Git repository URL box, enter the repository URL for your choice of framework.
In the Project slug box, enter my-first-static-web-app.
Select the Create project button and wait a moment while your repository is set up.
Create a static web app
Now that the repository is created, you can create a static web app from the Azure portal.
Navigate 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-gitlab. 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 the Go to resource button.
Select the Manage deployment token button.
Copy the deployment token value and set it aside in an editor for later use.
Select the Close button on the Manage deployment token window.
Create the pipeline task in GitLab
Next you add a workflow task responsible for building and deploying your site as you make changes.
Add deployment token
- Navigate to the repository in GitLab.
- Select Settings.
- Select CI/CD.
- Next to the Variables section, select the Expand button.
- Select the Add variable button.
- In the Key box, enter DEPLOYMENT_TOKEN.
- In the Value box, paste in the deployment token value you set aside in a previous step.
- Select the Add variable button.
Select the Repository menu option.
Ensure the main branch is selected in the branch drop down at the top.
Press the plus sign drop down and select New file.
Create a new file named
.gitlab-ci.ymlat the root of the repository. (Make sure the file extension is
Enter the following YAML into the file.
variables: API_TOKEN: $DEPLOYMENT_TOKEN APP_PATH: '$CI_PROJECT_DIR/src' deploy: stage: deploy image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy script: - echo "App deployed successfully."
The following configuration properties are used in the .gitlab-ci.yml file to configure your static web app.
$CI_PROJECT_DIRvariable maps to the repository's root folder location during the build process.
Property Description Example Required
Location of your application code. Enter
$CI_PROJECT_DIR/if your application source code is at the root of the repository, or
$CI_PROJECT_DIR/appif your application code is in a folder named
Location of your Azure Functions code. Enter
$CI_PROJECT_DIR/apiif your app code is in a folder named
Location of the build output folder relative to the
If your application source code is located at
$CI_PROJECT_DIR/app, and the build script outputs files to the
$CI_PROJECT_DIR/app/buildfolder, then set
API token for deployment.
Select the Commit changes button.
Select the CI/CD then Pipelines menu items to view the progress of your deployment.
Once the deployment is complete, you can view your website.
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 GitLab workflow that builds and publishes your application.
Before you can navigate 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.
- Navigate to the Overview window.
- Select the link under the URL label. Your website will load 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-gitlab resource group from the Overview section.
- Select the Delete resource group button at the top of the resource group Overview.
- Enter the resource group name static-web-apps-gitlab in the Are you sure you want to delete "static-web-apps-gitlab"? confirmation dialog.
- Select Delete.
The process to delete the resource group may take a few minutes to complete.
Submit and view feedback for