Azure DevOps

Trigger a DevOps Pipeline from the Azure DevOps Rest API Webhook

cubesys
Share this blog post on Twitter Share this blog post on Facebook Share this blog post on LinkedIn

Sometimes, you need the ability to trigger a DevOps build or release pipeline when a condition is met through a piece of code or from outside of the Azure DevOps environment.

In order to achieve this, we can utilise the DevOps API (Application Programming Interface) and send a Push request to a webhook URI (Uniform Resource Identifier) that will act as a trigger for a pipeline.

Creating a Personal Access Token

You can trigger any pipeline to run as long as you have the A Personal Access Token, which can be accessed from Personal Access Tokens within the user menu.

Here, you’ll want to create a new token.

The name is not important, I’ve used “triggerFromWebhook”. For expiry, I’ve set it to custom defined and made it last a year.

You’ll want to use a Custom Defined Scope, for which I’ve used the following settings.

It’s important that you copy the token that appears as you will not be able to access it again once the tab is closed. This token will be used as a basic authentication password.

That’s all we need to now trigger this pipeline from another location using a REST (Representational State Transfer) method.

Triggering the DevOps pipeline

You’ll use the following headers:

Authorization Basic {token}
Content-Type Application/json

And the following body:

{
           definitionId: _
}

The definition ID comes from the pipeline itself. It can be found inside the the URL of the pipeline you’re triggering.

In this case, the ID will be 26.

The endpoint we’re hitting will look something like this:

https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/release?api-version=7.1-preview.8

The API method will be Post. Attach the headers and body and the release pipeline should be triggered.

Triggering a build pipeline

To trigger a build pipeline, you’ll need a different set of body and URL.

https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineID}/runs?&api-version=7.1-preview.1

The body will contain:

{
                      “templateParameters”: {“inputName”:”inputValue”}
}

If no inputs are required, then we run this with an empty template parameters value. The headers and method are the same for both runs.

Leave a Comment

Related Articles

Endpoint Configuration Manager Intune Windows 11

Windows 11 – Check if your devices are Windows 11

With the release of the new Windows 11, you can check if your devices are ready for it using Intune/Endpoint Configuration Manager.

cubesys
Read More
Endpoint Configuration Manager Intune

Intune – Administrators can now locate devices

When you manage a fleet of devices, it is some time important to be able to locate these devices, especially when reported lost or stolen by end-users before requesting...

cubesys
Read More

About

  • Menu Item One
  • Menu Item Two
  • Menu Item Three

Services

  • Menu Item One
  • Menu Item Two
  • Menu Item Three

News

  • Menu Item One
  • Menu Item Two
  • Menu Item Three
Follow us on Facebook Follow us on LinkedIn Follow us on Twitter Follow us on Instagram