DAG
DAG

Reputation: 2620

Create a WebHook for AzureDevOps in .netcore

I'm trying to create a custom WebHook for our Team. This WebHook should be called when a build is successfully completed.

The steps I'm using are the following:

First I create a REST Api which will be my WebHook, this looks like this:

[ApiController]
[Route("[controller]")]
public class WebHookController : ControllerBase
{
    private readonly ILogger<WebHookController> _logger;

    public WebHookController(ILogger<WebHookController> logger)
    {
        _logger = logger;
    }

    // POST: /webhook
    [HttpPost]
    public async Task<IActionResult> Post() // Which object should my endpoint expect from AzureDevOps?
    {
        try
        {
             // Some logic here based on projectId   
        }
        catch (Exception ex)
        {
            _logger.LogError($"WebHookController: Post:  {ex}");
        }

        return BadRequest();
    }
}

Second I would host this API somewhere and then in AzureDevOps register this WebHook, like the below:

enter image description here

My question:

In the Post method what object is sent by AzureDevOps?

Upvotes: 1

Views: 672

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 18958

We provide one button Test which you can run it to get what are the JSON sent by Azure devops:

enter image description here

After run with Test, our system will run a virtual pipeline to send a request.


If trying with Test button, there's no need to input a valid URL values into URL blank. Just keep it not empty since it is a required argument.

After click on Test, change the tab to Request and you will see what you want:

enter image description here

Upvotes: 2

Related Questions