Exercise-10
10. Creating Build Pipelines: Building a Maven/Gradle Project with Azure Pipelines, Integrating Code Repositories (e.g., GitHub, Azure Repos), Running Unit Tests and Generating Reports
🎯 Objective:
To configure a self-hosted agent on a local machine, build a Maven or Gradle project using Azure DevOps Pipelines, run unit tests, and generate reports — all without incurring any Azure charges.
🔷 Theory Overview
✅ What is a Self-Hosted Agent?
A Self-hosted agent is a personal or institutional computer (e.g., your own laptop or lab PC) that runs Azure Pipelines jobs instead of using Microsoft-hosted (cloud) agents.
-
No billing or time limits
-
Full control over environment
-
Great for offline or classroom scenarios
🛠️ Steps to Build a Maven/Gradle Project with a Self-Hosted Agent
🖥️ Step 1: Prepare Your System (Self-Hosted Agent)
You’ll need:
-
A PC with Java, Maven or Gradle installed
-
Git installed
-
Internet access to download Azure agent
🔗 Step 2: Create an Azure DevOps Project (One-Time Setup by Instructor)
-
Go to https://dev.azure.com
-
Sign in and create a new organization (e.g.,
college-devops-org
) -
Create a project (e.g.,
BuildPipelineLab
)
⚙️ Step 3: Register Your Self-Hosted Agent
-
In Azure DevOps portal:
-
Go to Project Settings > Agent Pools
-
Click Default pool
-
Select New Agent > Choose OS (Windows/Linux/macOS)
-
-
Follow the steps shown to:
-
Download agent package
-
Extract it to a folder, e.g.,
C:\azagent
-
Run these commands:
-
-
Provide:
-
DevOps URL
-
Personal Access Token (PAT)
-
Agent name (e.g.,
labagent1
) -
Choose "run as a service" if prompted
-
-
Start the agent:
📦 Step 4: Push Code to Repository
-
Create a repository in Azure Repos or GitHub
-
Push your Maven/Gradle project there
🛠️ Step 5: Create azure-pipelines.yml
File in Your Repo
✅ For Maven:
✅ For Gradle:
🚀 Step 6: Run the Pipeline
-
Commit the YAML file to your repository.
-
Azure Pipelines will trigger automatically when changes are pushed.
-
The job will run on your own PC or lab machine (self-hosted agent).
📊 Step 7: View Unit Test Reports
-
Go to Pipelines > Runs
-
Click the latest run
-
Go to Tests tab to view results
If you don’t see test results:
-
Make sure you're using a testing framework like JUnit/TestNG.
-
Ensure reports are being generated in standard format (e.g.,
target/surefire-reports
for Maven).
✅ Advantages of Using Self-Hosted Agent
-
💸 Zero cost – no billing risk
-
🖥️ Use lab computers or personal laptops
-
🛠️ More control over software environment
-
📦 Ideal for educational institutions
Comments
Post a Comment