API for automating Azure DevOps ADO Build Pipelines – Guidelines
Today in this article, we will see how to use API for automating Azure DevOps ADO Build Pipelines process.
We will see an example of how to trigger Azure Pipelines build via API.
We will look over all 2 approaches to achieve the same,
- Build -Queue API
- Runs – Run Pipeline API
Today in this article, we will cover below aspects,
We will use the below API for the same.
Trigger an ADO build- using Queue API
Calling POST API
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?api-version=7.1-preview.7
Build pipeline With optional parameters
We can build a pipeline With optional parameters as explained in below example,
Calling POST API
POST https://dev.azure.com/{organization}/{project}/_apis/build/builds?ignoreWarnings={ignoreWarnings}&checkInTicket={checkInTicket}&sourceBuildId={sourceBuildId}&definitionId={definitionId}&api-version=7.1-preview.7
Input Parameters Explained
In the above Post request below are the input parameters,
- organization – The name of the Azure DevOps organization.
- project – Project ID or project name
- api version – Version of the API to use.
Request Body
- definition – The build number/name of the build.
Below is our sample repository,
https://dev.azure.com/jan2022-thecodebuzz/globalexceptionhandler/_build
Configuration and security
Let’s now configure the API to be invoked securely.
Step 1- Click on the User settings and set up the personal access token.
Define a name for this token and authorize the scope of access with this token. You can choose this token access for the Build pipeline trigger or release pipeline trigger etc.
Finally below is our URL and input request object defined,
Define URL
https://dev.azure.com/jan2022-thecodebuzz/globalexceptionhandler/_apis/build/builds?api-version=7.1-preview.7
Let’s now use Postman to execute the API. Please set up the Basic authentication in the Postman by setting up the Token name as UserName and Password as a personal access token.
Below is my request body,
{ "definition": { "id": 5 } }
Once you execute the POST API, please check your pipeline. You shall see it is executed and triggered for a build successfully,
References:
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.