Azure DevOps Releases

If you work with Azure DevOps, you probably automate a lot of tasks and actions, but you may also need to automate the Azure DevOps tasks. For instance, automating the project creation, automating the pipeline creation, etc. In this article, I will describe how to start an existing release in your Azure DevOps project using PowerShell and REST API. We will need to create a Personal Access Token.

To create a Personal Access Token, log into Azure DevOps in this organization. In the right top corner, click on the user icon:

Personal access tokens

Select “Personal access tokens“, then click on “New Token“:

New token

You can then define the scope of your application. The token defines how the application will interact with Azure DevOps Services. If you just need to read information, do not give extra permissions to the token.

Create a new personal access token

To access Azure DevOps Service Rest API, we need to send a basic authentication header. The basic authentication HTTP header will be in the following format:

The credential needs to be Base64 encoded. You can do it easily in PowerShell:

If you run this code, you should see something similar:

Run this code

Now that we know how to authenticate to Azure DevOps API, let’s run a simple task: how to list our Azure DevOps projects. First, you must use the authentication code

Then, use the “projects” URI:

Run the output variable and you will see your projects with some details:

Projects with some details

Now, I will explain how to run a release through PowerShell. Please, note that I will deploy an existing release, which means that the release is already deployed in my portal, and I will run once again the same release.

Releases

To run a release, you must find the release ID and the environment ID. To find these values, open the Azure DevOps portal, and find the expected release. Click the “Logs” tab:

Logs

Then, look at the URL address bar and search for the “release ID” and “environment ID”:

Rrelease ID

You will need these values in your PowerShell code later. Of course, if you want to run a new release, you first need to create a release first: https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/create?view=azure-devops-rest-6.0)

Now, let’s start by creating a PowerShell code that will start an existing release. First, add the authentication code with the Personal Access Token:

Add the following URI to request the release. To run an existing release, we need to update the definition and the status:

Here, we need to convert the parameters in the JSON format:

To finish, we use the “Patch” method to update the release status:

After running this code, the output variable will give you a lot of information about the release.

Information about the release

Switch back to the Azure DevOps portal and go to the release section to confirm the status:

Go to the release section to confirm the status

Open the release, go to the “History” tab. You will notice 3 steps:

  1. Queued (you can see the comment that we wrote in the PowerShell code)
  2. Triggered
  3. Succeeded

History tab

That’s all! The release has been deployed with PowerShell.

StarWind Backup Appliance (BA) is an industry-first all-NVMe backup appliance that provides unprecedented levels of backup and recovery speed. It comes as a tiny, pre-configured, ready-to-backup solution that eliminates the backup server storage bottleneck and fits even the strictest RTPO. Consisting of the best commodity hardware, your chosen hypervisor, and a StarWind SDS engine backed by 24/7/365 ProActive Support, StarWind BA ushers in a new age of a future-proof, eco-friendly, transparent, and reasonably priced backup infrastructure. Explore Backup Appliance from StarWind StarWind Backup Appliance Datasheet

You can read more information about how to update a release through API: https://docs.microsoft.com/en-us/rest/api/azure/devops/release/releases/update-release-environment?view=azure-devops-rest-6.0

Back to blog