In today’s article, I’m going to talk about release flow control. It is common to ask for approval in a release pipeline, especially when deploying to critical environments like Q&A and production.
Azure pipelines offer two types of deployment approvals:
We are only going to analyze the classic release pipeline experience because you can only define some general approvals at the environment level when using a multi-stage YAML pipeline, and those are de-facto pre-deployment approvals.
How to create and manage Pre- and Post-deployment approvals
Sign in to the Azure DevOps portal, and navigate to the Pipelines page. Once there, choose Release and click on New pipeline.
Create a second stage by clicking on the Add button and then New stage. In the window that appears, you will find different templates, such as Azure App Service deployment, Deploy a Node.js app to Azure App Service, and many more. For this demo, click on Empty job at the top.
To complete your release pipeline, you need to specify what to publish. To do so, click on Add an artifact and choose the source of the artifact. For this demo, I selected the latest version of the training project build, but you can choose the source that best fits your needs. Once you have entered all the required configuration, click Add to connect your artifact to the release pipeline.
Now it’s time to enable our post-deployment and pre-deployment approvals. Click on the user icon on the right side of stage 1. In the window that appears, click on Enable next to post-deployment approvals. Then, add an approver.
Next, click on the user icon on the left side of stage 3 and do the same, except this time for pre-deployment approvals.
Once you are finished, the release pipeline will look like this. You know that you have the approval in place because the user icons have a small checkmark on the bottom right side.
Save the pipeline and start a new release by clicking on Create release. In the window that appears we can specify the stages that execute, select the version of the artifact, and add a release description. For this demo, leave these configurations empty and click the Create button.
Once you have clicked the Create button, the release pipeline will start. Once stage 1 is done, it starts spanning approval. However, it is not yet marked as completed.
When you go back to the dashboard, the stage is still blue, which means that it’s in progress.
However, if we check the stage logs, we can see that all jobs have succeeded and are completed.
Approve the deployment by clicking on the Approve button. The stage will then be marked as completed, and the flow will move to stage 3. However, because we enabled the pre-deployment approval, the stage will go directly into the “waiting for approval” state.
If we check the stage logs, we see that no jobs have been executed.
When the approver approves the deployment, the user-icons will be marked green, and the deployment will be picked by an agent to be executed.
What are the differences between Pre- and Post-deployment approvals?
Using post-deployment approval, the artifact is deployed, and only then will the pipeline ask for approval. However, the stage will not be marked as completed until an approver approves the deployment.
Using the pre-deployment approval, the approver needs to mark the stage as approved before the deployment proceeds. The stage will then be marked as succeeded once it finishes.
- Azure pipelines official documentation: https://docs.microsoft.com/en-us/azure/devops/pipelines/release/approvals/approvals?view=azure-devops