Forum Discussion
surendra-p
Dec 03, 2024Copper Contributor
Can we integrate azure board in java application for retrieving projects, work items operations
I want to integrate the azure board in my spring boot java application to fetch the projects, iterations,work items. does azure provide the sdk for it so i can use that jar and integrate this kind of...
Kidd_Ip
Dec 05, 2024MVP
How about Azure DevOps Java SDK?
Add Azure DevOps SDK Dependency:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-devops-java-sdk</artifactId>
<version>1.0.0</version>
</dependency>
Authenticate with Azure DevOps:
- You will need a Personal Access Token (PAT) to authenticate with Azure DevOps. You can generate a PAT from your Azure DevOps account.
Fetch Projects, Iterations, and Work Items:
- Use the SDK to interact with Azure Boards. Here is an example of how you can fetch projects, iterations, and work items:
import com.microsoft.azure.devops.v5_1.core.CoreHttpClient; import com.microsoft.azure.devops.v5_1.work.WorkHttpClient; import com.microsoft.azure.devops.v5_1.workitemtracking.WorkItemTrackingHttpClient; import com.microsoft.azure.devops.v5_1.core.models.TeamProjectReference; import com.microsoft.azure.devops.v5_1.work.models.TeamSettingsIteration; import com.microsoft.azure.devops.v5_1.workitemtracking.models.WorkItem; import java.util.List; public class AzureBoardsIntegration { private static final String ORGANIZATION_URL = "https://dev.azure.com/your_organization"; private static final String PAT = "your_personal_access_token"; public static void main(String[] args) { CoreHttpClient coreClient = new CoreHttpClient(ORGANIZATION_URL, PAT); WorkHttpClient workClient = new WorkHttpClient(ORGANIZATION_URL, PAT); WorkItemTrackingHttpClient witClient = new WorkItemTrackingHttpClient(ORGANIZATION_URL, PAT); // Fetch projects List<TeamProjectReference> projects = coreClient.getProjects().getValue(); projects.forEach(project -> System.out.println("Project: " + project.getName())); // Fetch iterations for a specific project String projectId = "your_project_id"; List<TeamSettingsIteration> iterations = workClient.getTeamIterations(projectId, "your_team_id").getValue(); iterations.forEach(iteration -> System.out.println("Iteration: " + iteration.getName())); // Fetch work items List<WorkItem> workItems = witClient.getWorkItems("your_query").getValue(); workItems.forEach(workItem -> System.out.println("Work Item: " + workItem.getFields().get("System.Title"))); } }