Azure DevOps – Build Release Pipeline
Build release pipeline to automate deployment and complete the release. In our previous article (part 1), we’ve seen the basics of how to create a pipeline. This article will explore how to expand the basic pipeline developed in the previous blog. But first, let’s define it and examine its necessity before building a new release pipeline.
A conceptual procedure by which we put committed code into production is called a release pipeline. It is a technique for making the pipeline run. We complete the basic release process from a code deployment to live software. As a result, we can choose to make a release pipeline as quick or as genuine as we’d like.
You can use a release pipeline to pick up the artifacts published by your build and then deploy them to your Azure website.
To start creating a release pipeline, do the following:
- Open the Releases tab in Azure Pipelines, open the + drop-down in the list of release pipelines, and choose to Create release pipeline.
- The easiest way to create a release pipeline is to use a template. Select the Azure App Service Deployment template. Then choose Apply.
- If you created your new release pipeline from a build summary, check that the build pipeline and artifact are shown in the Artifacts section on the Pipeline tab. If you created a new release pipeline from the Releases tab, choose the + Add link and select your build artifact.
- Choose the Continuous deployment icon in the Artifacts section, check that the continuous deployment trigger is enabled, and add a filter to include the main branch.
- Open the Tasks tab and, with Stage 1 selected, configure the task property variables as follows:
- Azure Subscription: Select a connection from the list under Available Azure Service Connections or create a more restricted permissions connection to your Azure subscription. Suppose you use a TFS or do not see the desired Azure subscription in the list of subscriptions; manually set up the connection. If you are using Azure Pipelines and see an Authorize button next to the input, click on it to authorize Azure Pipelines to connect to your Azure subscription.
- App Service Name: Select the name of the web app from your subscription.
6. Save the release pipeline.
Step-by-Step Procedure to Configure a Release Pipeline
To create a release pipeline, choose “Releases” from the Left menu and click on “Create New Release Pipeline” or “New release Pipeline.” It displays a new release pipeline screen as shown below:
It will pop up to add a deployment template; if not, we can add a template under Stages. Since we already have our App service deployed in the Azure portal, We select the “Azure App Service deployment” template and click Apply.
Meanwhile, rename the stage name as your deployment environment. Typically, we create three stages separately for development, quality assurance, and production. We have chosen to deploy the production synch master branch of the source code, so we named the stage “Live.”
The artifacts from which the release binaries must be deployed are added under “Artifacts.” (Refer to Image 1).
Click on + Add to add the artifact. In our case, we have it under the drop folder in our build. Select the build pipeline from the build-load list and provide an appropriate alias name for reference. (Refer to Image 2).
Add stages to your release pipeline if you want to deploy multiple web apps because you control the order of deployment.
Typically, you want to use the same deployment methods with a test and a production stage to ensure your deployed apps will behave the same way.
Cloning an existing stage is a good way. Select the + Add drop-down list and choose Clone stage (the clone option is available only when an existing stage is selected).
Now click on the Job/Task under Live — Stage. Now it looks for the Azure subscription to connect to the deployment service.
Since we already have a subscription, we create a service connection with the procedure below to establish the connection between DevOps and app service. Click on “Manage” to redirect or Select “Project Settings” and choose Service Connections from the left menu to land on Service connection.
Use a service connection in Azure Pipelines
To deploy to Azure App Service, you’ll need to use an Azure Resource Manager service connection. The Azure service connection stores the credentials to connect Azure Pipelines or Azure DevOps Server to Azure.
The easiest way to get started with this task is to be signed in as a user who owns both the Azure DevOps Services organization and the Azure subscription. You won’t have to create the service connection in this case manually.
Click on “Create service connection.”
Select “Azure Resource Manager” and choose the “Service principal (automatic)” authentication method. This will automatically establish the connection.
Select the connection scope level as “Subscription” as we authenticate with Azure subscription. Since we logged in with the same user, the subscription will get populated. Choose the existing subscription and Resource group as our Stage. Provide a service connection name for reference.
Under Security, select “Grant access permission to all pipelines”; this will provide access to all pipelines created using this connection.
Once the connection is established successfully, redirect to the release pipeline and select our service connection as Azure subscription and the Project’s app service to be deployed as App service name.
Under the Agent Job, We need to select the artifact added to the release pipeline for deployment. The Agent pool and specification are the same as the build.
In Deploy Azure App Service, select the connection type as “Azure Resource Manager” and the service connection name as Azure Subscription, which will act as a gateway to the Azure portal. By default, the App service type is set to “Web App on windows” since the web application is hosted on the windows platform, let’s keep it as it is. Provide an appropriate name to the App Service name. Usually, the above values are pre-populated/suggested by Azure based on its mapping.
Under the Package or Folder section, browse and select the .zip file under the drop folder of the Release pipeline artifact. Each project will generate separate .zip files, but only one package per release stage can be processed in a pipeline. If a solution has more than one project, then each project should be configured as multiple stages, one below the other in the same pipeline. So that it can be executed in sequence and deployed changes can be updated in separate publish folders.
Select Variables > Variable groups, and then choose Link variable group (A group of variables in key-value pair to replace the value at release time). In a build pipeline, a list of available groups is displayed. In a release pipeline, link the variable group to one or more of these stages in the pipeline.
A variable group menu has the option to link all available variable groups. It has been linked to Live scoped, but you can also change the scope at the stage level. Once linked, these variable group values are available to pipelines, linked to sending the value to the pipeline, as shown below.
Once the CI/CD pipeline is finished and produces an artifact, a new release will be initiated.
We have shown how to use Azure DevOps to build a release pipeline with the CI/CD pipeline as the artifact source. Thanks for reading, and be sure to reach out to our experts at Payoda Technologies to learn more about building CI/CD pipelines to maximize the impact on your business.