Queueing an ADO (Azure DevOps) Build using URL Parameters in Jenkins
Jenkins and Azure DevOps (ADO) are two popular CI/CD tools used for building, testing, and deploying software. In this article, we will learn how to queue an ADO build using URL parameters in Jenkins. This can be very useful when integrating Jenkins with other systems or tools where automated triggering of ADO builds is required.
Prerequisites
To follow along with this article, you will need the following:
- A Jenkins instance with the appropriate plugins installed.
- An Azure DevOps account with a build definition configured.
Jenkins URL Parameters Plugin
To pass parameters through the URL in Jenkins, we need to install the URL Parameters Plugin. This plugin allows us to define parameters in the job configuration and access them through the URL to trigger the job.
Configuring the Jenkins Job
Let's create a new Jenkins job to trigger an ADO build. Here are the steps:
- Create a new Jenkins job.
- In the job configuration, under the Build Triggers section, check the Trigger builds remotely (e.g., from scripts) option.
- Add a String Parameter named adoBuildDefinitionId.
- In the job's build step, add the following code to trigger the ADO build:
#!/bin/sh ADO_TOKEN="your-ado-personal-access-token" ADO_URL="https://dev.azure.com/your-ado-organization" curl -X POST \ ${ADO_URL}/your-ado-project/_apis/build/builds?api-version=6.0 \ -H "Authorization: Bearer ${ADO_TOKEN}" \ -H "Content-Type: application/json" \ -d "{ "definition": { "id": ${params.adoBuildDefinitionId} } }"Replace the placeholders with your actual ADO organization, project, and personal access token.
Triggering the Jenkins Job through URL
Now that the Jenkins job is configured, we can trigger it through a URL. The URL will look like this:
http://your-jenkins-url/job/your-job-name/build?token=your-jenkins-build-token&adoBuildDefinitionId=your-ado-build-definition-id
Replace the placeholders with your actual Jenkins URL, job name, Jenkins build token, and ADO build definition ID.
- Installed the URL Parameters Plugin in Jenkins.
- Configured a Jenkins job to trigger an ADO build using the URL Parameters Plugin.
- Triggered the Jenkins job through a URL to queue an ADO build.