Creating a release pipeline in Azure DevOps is a straightforward process that involves defining the deployment process for your application. You can create a pipeline from scratch or clone an existing one.
To create a pipeline, you need to define a trigger, which can be based on a schedule, a specific event, or a manual trigger. This trigger will determine when the pipeline runs.
A pipeline consists of multiple stages, each of which represents a specific step in the deployment process. For example, you might have a stage for building and testing your application, followed by a stage for deploying it to production.
Setting Up Azure DevOps
To set up Azure DevOps, you'll need to create an organization and a project. Create an Azure DevOps Organization: Head to dev.azure.com and create an organization if you don’t have one.
You'll also need to connect your project to a source control system like GitHub or Azure Repos, where the application code is stored. Ensure your project is connected to a source control system.
To create a new project, click on “New Project” in your organization. You can then set up your project with the necessary configurations.
Note: Make sure your project is configured with your data factory.
Release Pipeline Configuration
To configure a release pipeline in Azure DevOps, you'll need to start with a new project, such as the one created by Azure DevOps Demo Generator. This will give you a foundation to work with.
You can add stages to your pipeline, which represent different environments like development, staging, and production. For example, you might have a "Development" stage followed by a "Production" stage.
Deployment targets are where you'll define where your application will be deployed, such as Azure App Service, Kubernetes, or VMs. You can also set environment-specific variables like connection strings, API keys, or environment URLs.
Here's a quick rundown of what you can configure in your release pipeline:
To ensure safe and successful deployments, Azure DevOps offers pre-deployment gates and approvals. These include manual approvals before a stage begins, post-deployment approvals after deployment, and automated gates for monitoring service health or ensuring successful tests.
Create New
To create a new release pipeline, you can follow these steps. First, navigate to the "Releases" section in Azure DevOps. Then, click on "New Pipeline" to open the release pipeline creation interface.
There are two ways to create a new release pipeline: by going to Pipelines > Releases and clicking on "New Pipeline", or by creating an empty job as specified in Step 1: Create New Release Pipeline.
To create a release pipeline, you'll need to link it to a build artifact, which can be generated by your build pipeline or connected directly to your source code repository.
Here are the steps to link a build artifact to your release pipeline:
- Select an Artifact: Choose the artifact generated by your build pipeline or connect it directly to your source code repository.
- Choose a Deployment Template: Select a template that aligns with your application's architecture, such as Azure App Service, Kubernetes, or virtual machines.
Remember, the template you choose will determine the specific steps and configuration required for your release pipeline.
Exercise 1: Configure
To configure a release pipeline, you need to navigate to the project created by Azure DevOps Demo Generator. Once you're there, you can set up gates in the release pipeline.
Azure DevOps allows you to have multiple stages in a release pipeline, each representing a different environment, such as development, staging, or production.
To add stages, click on "Add Stages" and create one or more stages, for instance, a "Development" stage followed by a "Production" stage.
Deployment targets can be defined in the stage settings, such as Azure App Service, Kubernetes, or VMs.
Variables can be set in the stage settings, including environment-specific variables like connection strings, API keys, or environment URLs.
Approvals can be set in the stage settings, either manual or automated, to ensure that the pipeline moves to the next stage only after certain conditions are met.
Here's a summary of the stage settings:
Release Pipeline Tasks
When creating a release pipeline in Azure DevOps, tasks are the specific steps that your pipeline will execute during deployment. Tasks can include deploying an application to an Azure App Service, running a database migration, or applying Kubernetes manifests.
To add tasks to each stage, click on the "Tasks" section in each stage. For example, if you're deploying to Azure App Service, you'll need to specify the service name and resource group.
You can use additional parameters to pass variables to the Ansible playbook, such as the path of the SSH key using ansible_ssh_private_key_file=$(pemKey.secureFilePath). Another option is to disable host key checking in your Ansible playbook by using the variable ansible_ssh_common_args='-o StrictHostKeyChecking=no'.
Add Tasks to Each Stage
In Azure DevOps, release pipeline tasks are the specific steps that your pipeline will execute during deployment. Tasks can be added to each stage, and they're essential for automating deployment processes.
To add tasks to each stage, navigate to the "Tasks" section in each stage. Here, you can add tasks such as deploying an application to an Azure App Service, running a database migration, or applying Kubernetes manifests.
For each task, configure the necessary parameters. For example, if you're deploying to Azure App Service, you'll need to specify the service name and resource group. This ensures that your deployment is successful and meets the required conditions.
Here's a breakdown of the types of tasks you can add to each stage:
By adding tasks to each stage, you can automate deployment processes and ensure that your releases are successful. Remember to configure the necessary parameters for each task to ensure a smooth deployment.
Configure Ansible Task
To configure the Ansible task in your release pipeline, start by adding the Ansible task and entering the playbook path. This is typically done by selecting the file and specifying the file path.
The Ansible task requires a playbook path, which can be selected from your Azure repository. For instance, if you have pushed your playbook and inventory file to your Azure repo branch, you can select them as artifacts in your release pipeline.
You can also use additional parameters to pass variables to the Ansible playbook. For example, you can use the variable `ansible_ssh_common_args='-o StrictHostKeyChecking=no'` to disable host key checking in your Ansible playbook.
In addition to passing variables, you can also use additional parameters to pass the path of the SSH key. This can be done using the command `ansible_ssh_private_key_file=$(pemKey.secureFilePath)`.
Retrieve Key Vault Secrets
You can get secrets from Azure Key Vault using Azure Pipelines release. There are two ways to handle secrets.
To use the first method, add secrets to a parameters file. This file needs to be in the publish branch as well. The parameters file should be in the format of a JSON object with a "reference" section that includes the key vault ID and secret name.
Add an Azure Key Vault task before the Azure Resource Manager Deployment task to use the second method. This task will pull the secret from the key vault automatically.
Here are the two methods summarized in a table:
You should choose the method that best fits your needs. If you need more control over the secret retrieval process, the second method might be a better choice.
Frequently Asked Questions
What is the release pipeline in Azure DevOps?
In Azure DevOps, a Release Pipeline is a multi-staging system that consumes artifacts and performs follow-up actions. It's a crucial part of a blue/green deployment strategy, where two identical environments are created for seamless deployment.
What is the difference between build and release pipeline in Azure DevOps?
In Azure DevOps, a Build Pipeline generates artifacts from source code, while a Release Pipeline consumes these artifacts and performs follow-up actions in a multi-staging system. This distinction enables efficient and automated deployment processes.
What is the difference between deploy and release in DevOps?
In DevOps, deployment focuses on continuous code delivery, while release ensures controlled and coordinated delivery of new features to end-users. Understanding the difference between these two phases is key to successful software delivery and user adoption.
How to run release pipeline manually in Azure DevOps?
To run a release pipeline manually in Azure DevOps, navigate to Pipelines, select the pipeline, and click Run Pipeline. This will queue the job and initiate the redeployment process.
How do I trigger pipeline from release in Azure?
To trigger a pipeline from a release in Azure, navigate to Releases, select your release definition, and enable the Scheduled release trigger under the Artifacts section. From there, you can specify your release schedule and set up multiple triggers as needed.
Sources
- https://www.azuredevopslabs.com/labs/vstsextend/releasegates/
- https://learn.microsoft.com/en-us/azure/devops/pipelines/get-started/what-is-azure-pipelines
- https://medium.com/@S3CloudHub./how-to-build-and-configure-a-release-pipeline-in-azure-devops-73ca1b1b8ee0
- https://dzone.com/articles/run-anisble-playbook-from-azure-devops-release-pip
- https://learn.microsoft.com/en-us/azure/data-factory/continuous-integration-delivery-automate-azure-pipelines
Featured Images: pexels.com