AzureDevOps integrates third party CI pipeline components through a Pull Request Status API (example usage with node.js). The end goal of the status API is to allow you to integrate any number of 3rd party tooling into your pull request validation processes. Hopefully creating something that looks like this:
The Build succeeded link comes from the built-in Build Policy of Azure DevOps Branch Protection. But, for any other service, you’ll need to integrate it’s results using an external service. That’s how the Deploy succeeded link was created in the screenshot above.
There are examples on how to use the API for external services (like the node.js example), but I didn’t run across any examples for powershell. So, here’s a quick example.
The example code:
- Load’s up some dlls from AzureDevOps .NET Client Libraries.
- Loads up the VSTeam powershell module.
- Signs into Azure DevOps using your Personal Access Token (both VSTeam and the .NET Client libraries need to be signed into separately).
- Uses VSTeam to retrieve your Project’s internal Guid.
- You can do this with the .NET libraries too. I just want to support the usage of the VSTeam module.
- Uses the .NET Libraries to retrieve your Repositories internal Guid.
- Creates a GitPullRequestStatus object and populates it with some information.
- Uses CreatePullRequestStatusAsync to update the status.
- The great part of CreatePullRequestStatusAsync is that the display will always show the most recently supplied status for an integration component. So, you don’t have to worry about “updating” the status. Just call CreatePullRequestStatusAsync repeatedly throughout your process to update the status.
0 comments:
Post a Comment