Using Azure DevOps REST API to start multiple releases with Azure Logic Apps


In our last article, we looked at how we could leverage the Azure DevOps REST API to trigger multiple releases.

This is useful when rebuilding an environment: first we release the shared infrastructure then each service on top of it.

In this article, we’ll see an implementation example using Azure Logic Apps.

There are many reasons why I chose Azure Logic Apps:

  1. I like it
  2. It rocks
  3. It is serverless: this isn’t frivolous here since I’m using that seldomly at random time
  4. It is great at orchestrating tasks
  5. It has great logging which we can visualize as an overlay on the designer
  6. It is great for interaction with JSON-based REST API

There is integration betweeen Logic Apps & Azure DevOps. Here I’m going to use the REST API directly instead. I do not like the authentication mechanism of those connectors. They use delegation from my own account and that delegation must be renewed manually.

The solution I give here is a mere example. I thought about doing something generic and quickly give up. The complexity would have defy the purpose.

Our example runs two releases. It first runs the “top-level” release, wait for its success and then runs the other one.

There are a couple of patterns in the sample I would recommend using for a real solution:

  • Make API call into separate Logic Apps (e.g. get-release) ; this makes the orchestration apps much simpler / cleaner
  • Grab only a few key elements of the payload to return to orchestration
  • Do not spread secrets around, pass them (securely) in Logic Apps invocation

The code is available on GitHub.

Deploy example

The sample can easily be deployed by clicking the following button:

Deploy button

There are six parameters:

Name Description
Pat A Personal Access Token (PAT) allowing read/write/execute of releases in the DevOps organization
Organization Name of DevOps organization
Top-project Name of the top-project, i.e. the project to deploy first
Second-project Name of the second project, i.e. the one to deploy after the first one succeeded
Top-project release definition ID The release definition ID of the top-project
Second-project release definition ID The release definition ID of the second-project

This should deploy very quickly and yield three Logic Apps:

Logic Apps

Let’s look at each of them.

Release Orchestration

This app orchestrates the workflow:

Release Orchestration

It doesn’t receive any parameter. The ARM template pushes its parameters to the Logic Apps parameters.

The workflow is straightforward:

  1. Create the top-project release
  2. Grab its release ID
  3. Loop until the release is completed
  4. If the release is a success, it creates the second-project release

The loop is quite straightforward itself

Until

  1. Wait for 20 seconds
  2. Get the release status
  3. Parse the result
  4. Grab the result
  5. Run until the status isn’t inProgress

We can run this Logic Apps and it should orchestrate the two releases.

Create Release

This app is a thin wrapper around the Create Release API.

Create Release

  1. Converts the PAT to its base-64 representation, prepending a colon (:) to it
  2. Creates the URL for the API
  3. Invoke the API via an HTTP Request
  4. Fails if the API failed
  5. Succeeds if it did succeed, sending a reduced payload

Get Release Status

Similarly, this app is a thin wrapper around the Get Release API.

Get Release Status

  1. Converts the PAT to its base-64 representation, prepending a colon (:) to it
  2. Creates the URL for the API
  3. Invoke the API via an HTTP Request
  4. Fails if the API failed
  5. Succeeds if it did succeed, sending a reduced payload

The parsing of the results is slightly more involved here since there is an array. We need specialized tasks for this.

Summary

We gave a simple example on how to orchestrate multiple releases using Azure DevOps API.

Leveraging Azure Logic Apps made it quite easy to orchestrate those APIs without writing any code.

Advertisements

One thought on “Using Azure DevOps REST API to start multiple releases with Azure Logic Apps

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s