Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

How to Start Azure DevOps Releases Using PowerShell?

  • November 2, 2021
  • 8 min read
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.

 

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.

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

Hey! Found Nicolas’s insights useful? Looking for a cost-effective, high-performance, and easy-to-use hyperconverged platform?
Taras Shved
Taras Shved StarWind HCI Appliance Product Manager
Look no further! StarWind HCI Appliance (HCA) is a plug-and-play solution that combines compute, storage, networking, and virtualization software into a single easy-to-use hyperconverged platform. It's designed to significantly trim your IT costs and save valuable time. Interested in learning more? Book your StarWind HCA demo now to see it in action!