Skip to content

Commit 37832c7

Browse files
authored
Merge pull request #312449 from v-thepet/apps4
Freshness Edit: App Service 4
2 parents 7484ac2 + edc58e0 commit 37832c7

1 file changed

Lines changed: 82 additions & 81 deletions

File tree

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
11
---
2-
title: Deploy with Azure Pipelines
3-
description: Learn how to use Azure Pipelines to deploy your custom Windows container to App Service from a CI/CD pipeline.
2+
title: Deploy a container app using Azure Pipelines
3+
description: Learn how to deploy your custom Windows container app stored in Azure Repos to Azure App Service via an Azure Pipelines CI/CD pipeline.
44
ms.topic: how-to
5-
ms.date: 6/10/2024
5+
ms.date: 03/02/2026
66
author: jefmarti
77
ms.author: jefmarti
88
ms.service: azure-app-service
9+
# As a developer, I want to use Azure Pipelines to deploy a Windows container app to App Service so that I can deploy my containerized apps stored in Azure Repos to App Service using CI/CD.
10+
---
911

10-
# As a developer, I want to deploy a custom Windows container to App Service from a CI/CD pipeline.
12+
# Deploy a container app using Azure Pipelines
1113

12-
---
14+
This article describes how to deploy a Windows container application to Azure App Service from an Azure Repos Git repository using Azure Pipelines continuous integration and continuous delivery (CI/CD). Azure Repos and Azure Pipelines are complimentary Azure DevOps services that enable you to host, build, plan, and test your code using any platform and cloud. The pipeline is defined as a YAML file in the root directory of your repository.
1315

14-
# Deploy a custom container to App Service using Azure Pipelines
16+
## Prerequisites
1517

16-
Azure DevOps enables you to host, build, plan, and test your code with complimentary workflows. Using Azure Pipelines as one of these workflows allows you to deploy your application with CI/CD that works with any platform and cloud. A pipeline is defined as a YAML file in the root directory of your repository.
18+
- An Azure account with an Azure Container Registry registry instance and a Web App created in Azure App Service. [Create an Azure account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
19+
- An Azure DevOps organization and project, with a Windows app that runs in a Docker container and a supporting Dockerfile checked into an [Azure Repos](https://docs.github.com/get-started/quickstart/create-a-repo) repository in your project.
20+
- The appropriate user roles or permissions to create and manage Azure resources and Azure DevOps projects, pipelines, repos, and service connections. For more information, see [Manage security in Azure Pipelines](/azure/devops/pipelines/policies/permissions).
1721

18-
In this article, we use Azure Pipelines to deploy a Windows container application to App Service from a Git repository in Azure DevOps. It assumes you already have a .NET application with a supporting dockerfile in Azure DevOps.
22+
## Add a service connection
1923

20-
## Prerequisites
24+
Before creating this pipeline, you must create an Azure service connection to Azure Container Registry. In Azure DevOps, select **Project Settings** for your project, and create the service connection by following the instructions at [Create a service connection](/azure/devops/pipelines/library/service-endpoints#create-a-service-connection).
2125

22-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
23-
- An Azure DevOps organization. [Create one for free](/azure/devops/pipelines/get-started/pipelines-sign-up).
24-
- A working Windows app with Dockerfile hosted on [Azure Repos](https://docs.github.com/get-started/quickstart/create-a-repo).
26+
To create the service connection for this project and pipeline, choose **Docker Registry** and then choose **Azure Container Registry** as the registry type. After you create the service connection, copy its **ID** to use in a later step.
2527

26-
## Add a Service Connection
27-
Before you create your pipeline, you should first create your Service Connection since you'll be asked to choose and verify your connection when creating your template. A Service Connection allows you to connect to your registry of choice (ACR or Docker Hub) when using the task templates. When adding a new service connection, choose the Docker Registry option. The following form asks you to choose Docker Hub or Azure Container Registry along with pertaining information. To follow along with this tutorial, use Azure Container Registry. You can create a new Service Connection following the directions [here](/azure/devops/pipelines/library/service-endpoints).
28+
## Create and configure the pipeline
2829

29-
## Secure your secrets
30-
Since we're using sensitive information that you don't want others to access, we use variables to protect our information. Create a variable by following the directions [here](/azure/devops/pipelines/process/variables).
30+
Create and configure a pipeline to run the steps for building the container, pushing to the registry, and deploying the image to App Service.
3131

32-
1. To add a variable, click the **Variables** button next to the **Save** button in the top-right of the editing view for your pipeline.
33-
1. Select the **New Variable** button and enter your information. Add the variables below with your own secrets appropriate from each resource.
32+
Create the pipeline by following these steps:
3433

35-
- vmImageName: 'windows-latest'
36-
- imageRepository: 'your-image-repo-name'
37-
- dockerfilePath: '$(Build.SourcesDirectory)/path/to/Dockerfile'
38-
- dockerRegistryServiceConnection: 'your-service-connection-number'
34+
1. In your project in Azure DevOps, select **Pipelines** from the left navigation menu and then select **Create** or **Create Pipeline**.
35+
1. On the **Where is your code** screen, select **Azure Repos Git**.
36+
1. On the **Choose a repository** screen, select the repository that contains your app.
37+
1. On the **Configure your pipeline** screen, select **Starter pipeline**.
38+
1. Select the dropdown arrow next to **Save and run** at upper right and select **Save**, and then select **Save** again. Don't run the pipeline yet.
3939

40-
## Create a new pipeline
41-
Once your repository is created with your .NET application and supporting dockerfile, you can create your pipeline following these steps.
40+
### Create variables
4241

43-
1. Navigate to **Pipelines** on the left menu bar and click on the **Create pipeline** button
44-
1. On the next screen, select **Azure Repos Git** as your repository option and select the repository where your code is
45-
1. Under the Configure tab, choose the **Starter Pipeline** option
46-
1. Under the next Review tab, click the **Save** button
42+
You can create pipeline variables to reuse frequently used values or protect secure information you don't want others to access. For more information, see [Define variables](/azure/devops/pipelines/process/variables).
4743

48-
## Build and push image to Azure Container Registry
44+
1. Select **Edit** at upper right on the pipeline page, and then select **Variables** at upper right on the editing page.
45+
1. On the **Variables** screen, select **New variable**.
46+
1. Add the following name/value pairs, using your own information for the placeholder values. Select **OK** after adding each variable and then select **+** to add the next variable. If the value is a secret, select the checkbox to **Keep this value secret**.
4947

50-
After your pipeline is created and saved, you'll need to edit the pipeline to run the steps for building the container, pushing to a registry, and deploying the image to App Service. To start, navigate to the **Pipelines** menu, choose your pipeline that you created and click the **Edit** button.
48+
- vmImageName: windows-latest
49+
- imageRepository: \<repository-name>
50+
- dockerfilePath: $(Build.SourcesDirectory)/\<folder-path>/Dockerfile
51+
- dockerRegistryServiceConnection: \<service-connection-ID>
5152

52-
First, you need to add the docker task so you can build the image. Add the following code and replace the Dockerfile: app/Dockerfile with the path to your Dockerfile.
53+
1. After adding the variables, select **Save** on the **Variables** screen, and select **Save** again on the pipeline page.
54+
55+
### Add a task to build and push the image
56+
57+
Replace all of the existing code in the *azure-pipelines.yml* starter file with the following code. This code adds a Docker task that builds and pushes the image to Azure Container Registry. The code uses the `$(<variable-name>)` syntax to call the variables you set up earlier.
5358

5459
```yaml
5560
trigger:
56-
- main
57-
58-
pool:
59-
vmImage: 'windows-latest'
61+
- main
6062

61-
variables:
62-
vmImageName: 'windows-latest'
63-
imageRepository: 'your-image-repo-name'
64-
dockerfilePath: '$(Build.SourcesDirectory)/path/to/Dockerfile'
65-
dockerRegistryServiceConnection: 'your-service-connection-number'
63+
pool:
64+
vmImage:
65+
$(vmImageName)
6666

67+
stages:
6768
- stage: Build
6869
displayName: Build and push stage
6970
jobs:
@@ -79,15 +80,13 @@ trigger:
7980
repository: $(imageRepository)
8081
dockerfile: $(dockerfilePath)
8182
containerRegistry: $(dockerRegistryServiceConnection)
82-
tags: |
83-
$(tag)
8483
```
8584
86-
## Add the App Service deploy task
85+
### Add the App Service deploy task
8786
88-
Next, you need to set up the deploy task. This requires your subscription name, application name, and container registry.
87+
Add the deployment task to Azure App Service. This task requires you to specify your Azure subscription name, web app name, and container registry name.
8988
90-
1. Add a new stage to the yaml file by pasting the code below.
89+
1. Add the deployment stage to the *azure-pipelines.yml* file by adding the following code to the end of the file.
9190
9291
```yaml
9392
- stage: Deploy
@@ -100,45 +99,49 @@ Next, you need to set up the deploy task. This requires your subscription name,
10099
steps:
101100
```
102101
103-
1. Navigate to the **Show assistant** tab in the upper right hand corner and find the **Azure App Service deploy** task and fill out the following form:
102+
1. Place your cursor on a new line at the end of the file, and if necessary, select the **Show assistant** icon at right to show the **Tasks** pane. In the **Tasks** pane, search for and select the **Azure App Service deploy** task.
103+
1. On the **Azure App Service deploy** screen, complete the following information:
104104
105-
- Connection type: Azure Resource Manager
106-
- Azure subscription: your-subscription-name
107-
- App Service type: Web App for Containers (Windows)
108-
- App Service name: your-app-name
109-
- Registry or Namespace: your-azure-container-registry-namespace
110-
- Image: your-azure-container-registry-image-name
105+
- **Connection type**: Select **Azure Resource Manager**.
106+
- **Azure subscription**: Select your Azure subscription name and ID. If necessary, select **Authorize**.
107+
- **App Service type**: Select **Web App for Containers (Windows)**.
108+
- **App Service name**: Select or enter your App Service web app name.
109+
- **Registry or Namespace**: Enter your Azure Container Registry instance name.
110+
- **Image**: Enter the repository name where your code is stored.
111111
112-
1. Click the **Add** button to add the task below:
112+
1. Select **Add**. The following code appends to the end of the file, with your values replacing the placeholders.
113113
114114
```yaml
115-
- task: AzureRmWebAppDeployment@4
116-
inputs:
117-
ConnectionType: 'AzureRM'
118-
azureSubscription: 'my-subscription-name'
119-
appType: 'webAppHyperVContainer'
120-
WebAppName: 'my-app-name'
121-
DockerNamespace: 'myregsitry.azurecr.io'
122-
DockerRepository: 'dotnetframework:12'
115+
- task: AzureRmWebAppDeployment@4
116+
inputs:
117+
ConnectionType: 'AzureRM'
118+
azureSubscription: '<your subscription name (subscription ID)>'
119+
appType: 'webAppHyperVContainer'
120+
WebAppName: '<your App Service web app name>'
121+
DockerNamespace: '<your Azure Container Registry instance name>'
122+
DockerRepository: '<your repository name>'
123123
```
124124
125-
After you've added the task the pipeline is ready to run. Click the **Validate and save** button and run the pipeline. The pipeline goes through the steps to build and push the Windows container image to Azure Container Registry and deploy the image to App Service.
125+
## Run the pipeline
126+
127+
The pipeline is now ready to run.
128+
129+
1. Select **Validate and save**, and select **Save** again.
130+
1. Select **Run**, and select **Run** again.
126131
127-
Below is the example of the full yaml file:
132+
The pipeline goes through the steps to build and push the Windows container image to Azure Container Registry and deploy the image to App Service.
133+
134+
The following code shows the full *azure-pipelines.yml* pipeline definition file with example values.
128135
129136
```yaml
130137
trigger:
131-
- main
132-
133-
pool:
134-
vmImage: 'windows-latest'
138+
- main
135139

136-
variables:
137-
vmImageName: 'windows-latest'
138-
imageRepository: 'your-image-repo-name'
139-
dockerfilePath: '$(Build.SourcesDirectory)/path/to/Dockerfile'
140-
dockerRegistryServiceConnection: 'your-service-connection-number'
140+
pool:
141+
vmImage:
142+
$(vmImageName)
141143

144+
stages:
142145
- stage: Build
143146
displayName: Build and push stage
144147
jobs:
@@ -154,8 +157,6 @@ trigger:
154157
repository: $(imageRepository)
155158
dockerfile: $(dockerfilePath)
156159
containerRegistry: $(dockerRegistryServiceConnection)
157-
tags: |
158-
$(tag)
159160

160161
- stage: Deploy
161162
displayName: Deploy to App Service
@@ -166,11 +167,11 @@ trigger:
166167
vmImage: $(vmImageName)
167168
steps:
168169
- task: AzureRmWebAppDeployment@4
169-
inputs:
170-
ConnectionType: 'AzureRM'
171-
azureSubscription: 'my-subscription-name'
172-
appType: 'webAppHyperVContainer'
173-
WebAppName: 'my-app-name'
174-
DockerNamespace: 'myregsitry.azurecr.io'
175-
DockerRepository: 'dotnetframework:12'
170+
inputs:
171+
ConnectionType: 'AzureRM'
172+
azureSubscription: 'mysubscription(00000000-0000-0000-0000-000000000000)'
173+
appType: 'webAppHyperVContainer'
174+
WebAppName: 'myWindowsDockerSample'
175+
DockerNamespace: 'mycontainerregistry'
176+
DockerRepository: 'myrepository'
176177
```

0 commit comments

Comments
 (0)