Azure-pipelines-tasks: Trigger a build in Azure DevOps using Services hooks

Created on 14 May 2019  路  15Comments  路  Source: microsoft/azure-pipelines-tasks

Hi Team,

I am trying to queue a build in azure devops (VSTS) using Service Hooks.

I am able to trigger a Jenkins build using the service Hooks
example
http://user:[email protected]:8080/job/job-name/build?token=token.

But I need to trigger a build in VSTS using Service hooks
Please guide me

regards,
Naidu

Build question

All 15 comments

Hi Josh Gross
Thanks for your response,

I tried these approach but its not working for me .
Please find the below attachment what I followed
VSTSBuildThroughServiceHooks.docx

Please suggest me

Kind Regards,
Naidu

@Naidul What is your use case? I'm not sure if Service Hooks is the correct method

Hi Joshmgross,

Sorry for the delay...

My use case is when ever a work item state updated(Active --> Resolved/Active __> Closed/) then build needs to trigger automatically based on this work item state update event..

Could you please help on this

Regards,
Naidu

@Naidul
Service Hooks are mostly used for external services, but it might work in this scenario with a WebHook (https://docs.microsoft.com/en-us/azure/devops/service-hooks/services/webhooks?view=azure-devops)

I see in your attached doc that the URL is incorrect, you'll want to fill in the fields for {organization} and {project} with the name of your Azure DevOps org and project

You'll also need to somehow specify the definition to queue the build, this goes in the request body but that won't be in the Service Hook event. See https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/queue?view=azure-devops-rest-5.0#request-body

You could also try setting up a server or function to receive these events and then queue a build from them. That way you'll be able to specify all the necessary information to queue the build.

@Naidul
Naidu, did you ever get this working, as I have a similar requirement

To sum it up: There is no real Webbhook support, because Webhook normally don't support POST data .. jut a simple get . The API should allow to pass the build definition id via http query param

No way to trigger a build using any API from Azure DevOps ?

So... any info about this issue?

I'm able to start or canclel using this curl (reverse engineered from UI). Same hat works below for release pipelines will also work for build. You will find the url, but i think it's "Build/builds/" instead of "Release/releases"
"status":8 is cancel and so far i remember "status":1 (or 0?) was start. Juts try it out

curl -u "username:${DEVOPS_TOKEN}" -X PATCH -H "Content-Type: application/json" -silent --output /dev/null --data '{"status":8,"scheduledDeploymentTime":null,"comment":"Skip Staging because '"${msg}"' "}' https://vsrm.dev.azure.com/daimler-mic/devdataproc/_apis/Release/releases/${RELEASE_RELEASEID}/environments/${RELEASE_ENVIRONMENTID}/?api-version=6.0-preview.6

curl -u "username:${DEVOPS_TOKEN}" -X PATCH -H "Content-Type: application/json" -silent --output /dev/null --data '{"status":1,"scheduledDeploymentTime":null,"comment":"Start Staging"}' https://vsrm.dev.azure.com/daimler-mic/devdataproc/_apis/Release/releases/${RELEASE_RELEASEID}/environments/${RELEASE_ENVIRONMENTID}/?api-version=6.0-preview.6

I was trying to find a solution for a similar problem, where I wanted to monitor a docker base image update in the Azure Container Registry (ACR).

I found three options:

  1. Trigger downstream builds from a TriggerPipeline task in your Azure DevOps pipeline's yaml file.
  2. Create a Service Hook in the Azure DevOps project settings, then link it to an Azure Logic App that would _Queue a new build_.
  3. Create a webhook for the base image in ACR, then link it to an Azure Logic App that would _Queue a new build_.

I would recommend solution (3) because it is easy to set up, more universal and it keeps your build pipelines and project settings clean.

Yes, I am curious as well about this problem, because I try to integrate with the GitHub repository webhooks, but using Personal Access Token. When you specify webhook there, you can only specify URL so it would be very valuable to run it with a build queue in the address:
image

In addition to the REST API, one of the other ways could be to use a combination of LogicApp and DevOps Service. LogicApp has a great Azure DevOps task that will trigger a build / release and pass it parameters as well. The LogicApp can be exposed as either a simple webhook or HTTP POST API (if you want to pass parameters). We plan to use this to integrate GitLab (event based outbound webhook) with Azure DevOps in one of our scenarios. Not sure if this the best solution though.

There is a relatively new feature described in the Sprint 172 Release Notes where one can trigger a YAML build via a Service Connection/Service Hook combination. I think this addresses this request.

It looks like this request has been addressed so I'm going to close here. If this is still an issue I'd recommend opening a ticket at https://developercommunity.visualstudio.com/spaces/21/index.html since this repo is mostly for tasks related issues

Was this page helpful?
0 / 5 - 0 ratings