DEVOPS LAB
Exam-Day Quick Reference
BCSL657D | Semester VI | Experiments 1–11
All commands are copy-paste ready, in execution order.
Each step shows: the command → what it does → what success looks like.
1CR23IS023 — CMR Institute of Technology
How to Use This Guide
This is condensed from your lab manual into pure execution steps. Skip the theory paragraphs in the exam —
examiners mostly want to see your terminal output match the expected result.
Order to revise in (5 minutes each):
1. Exp 1–4: Maven & Gradle — install, create project, build, run, migrate
2. Exp 5–6: Jenkins — install, unlock, CI pipeline with Git
3. Exp 7–8: Ansible — inventory, playbook, deploy artifact from Jenkins
4. Exp 9–11: Azure DevOps — org/project, build pipeline, release pipeline
Tip: In the exam, run commands in this exact order in ONE terminal session per experiment. If a command fails, re-
read the error line — 90% of marks are lost to typos in paths, not concepts.
Experiment 1 — Maven & Gradle: Install & Setup
Goal: Install Java, Maven, Gradle and verify each. Know the Maven vs Gradle differences table (commonly asked
theory).
Step 1 — Update system & install Java
sudo apt update
sudo apt upgrade -y
sudo apt install openjdk-17-jdk -y
java -version
✔ Expect to see: openjdk version "17.x.x" ...
Step 2 — Install Maven
sudo apt install maven -y
mvn -version
✔ Expect to see: Apache Maven 3.6.x, Java version: 17..., OS name: "linux"
Step 3 — Install Gradle
Option A (quick, from Ubuntu repo):
sudo apt-get install gradle -y
gradle -v
Option B (recommended — latest version):
wget [Link]
sudo unzip -d /opt/gradle [Link]
echo "export PATH=\$PATH:/opt/gradle/gradle-8.0/bin" >> ~/.bashrc
source ~/.bashrc
gradle -v
✔ Expect to see: Gradle 8.0 ... Build time, Groovy, JVM, OS details printed.
Maven vs Gradle — exam-ready 1-liners
Aspect Maven Gradle
Config file [Link] (XML) [Link] (Groovy/Kotlin)
Style Rigid, convention-based Flexible, programmable
Build model Fixed lifecycle Task-based, customizable
Speed Slower (no incremental) Faster (incremental + cache)
Best for Beginners, legacy projects Large/multi-module, Android
Experiment 2 — Maven: Create Project, POM, Plugins
Step 1 — Generate a Maven project
mvn archetype:generate -DgroupId=[Link] -DartifactId=MyMavenApp \
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd MyMavenApp
✔ Expect to see: BUILD SUCCESS, and a new MyMavenApp/ folder with [Link] + src/
Step 2 — Know the structure
MyMavenApp/
├── [Link]
└── src
├── main/java/com/example/[Link]
└── test/java/com/example/[Link]
Step 3 — Key [Link] pieces to recognise
groupId / artifactId / version = project identity. <dependencies> = libraries (e.g. JUnit). <build><plugins> =
compiler + surefire (test runner).
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
Step 4 — Build, test, package, clean
mvn compile # compiles source
mvn test # runs unit tests
mvn package # compiles + tests + builds JAR in target/
mvn clean # deletes target/ (previous build output)
✔ Expect to see: "BUILD SUCCESS" and a JAR at target/[Link]
Exam tip: If asked to show the JAR exists, run: ls -l target/*.jar
Experiment 3 — Gradle: Project, Build Scripts, Tasks
Step 1 — Create project
mkdir HelloGradle && cd HelloGradle
gradle init --type java-application
✔ Expect to see: BUILD SUCCESSFUL, generates [Link], [Link], src/main/java/[Link]
Step 2 — Minimal [Link] (Groovy DSL)
plugins {
id 'java'
id 'application'
}
group = '[Link]'
version = '1.0'
repositories { mavenCentral() }
dependencies {
testImplementation 'junit:junit:4.13.2'
}
application {
mainClass = '[Link]'
}
task hello {
doLast { println 'Hello, Gradle!' }
}
Step 3 — Run core commands
gradle build # compile + test + jar
gradle run # runs the application's main class
gradle hello # runs your custom task
✔ Expect to see: BUILD SUCCESSFUL ... and "Hello, Gradle!" printed by the custom task
Step 4 — Task dependency (one-liner to remember)
task greet(dependsOn: build) {
doLast { println 'Build is complete! Time to celebrate!' }
}
Kotlin DSL equivalent: [Link]("hello") { doLast { println("Hello!") } } — same idea, different syntax, file is
[Link]
Experiment 4 — Build/Run with Maven, Migrate to Gradle
Part A — Maven: build & run
mvn archetype:generate -DgroupId=[Link] -DartifactId=HelloMaven \
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd HelloMaven
mvn package
java -cp target/[Link] [Link]
✔ Expect to see: Hello World!
Part B — Migrate to Gradle
mkdir HelloMavenGradle && cd HelloMavenGradle
gradle init --type java-application
Copy [Link] content from HelloMaven into the same package path:
mkdir -p src/main/java/com/example
mv src/main/java/[Link] src/main/java/com/example/
Edit [Link] — set the correct main class:
application {
mainClass = '[Link]'
}
gradle build
gradle run
✔ Expect to see: BUILD SUCCESSFUL, then Hello World! printed by gradle run
Key concept to say out loud in viva: Same source code, two different build tools — Maven uses XML lifecycle,
Gradle uses task graph. Migration only needs path/package alignment + mainClass config.
Experiment 5 — Jenkins: Install & First-Time Setup
Step 1 — Install Java + add Jenkins repo
sudo apt update && sudo apt upgrade -y
sudo apt install openjdk-17-jdk -y
wget -q -O - [Link] | sudo apt-key add -
sudo sh -c 'echo deb [Link] binary/ >
/etc/apt/[Link].d/[Link]'
sudo apt update
sudo apt install jenkins -y
Step 2 — Start Jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
✔ Expect to see: active (running) in green
Step 3 — Unlock Jenkins (browser)
1. Open browser → [Link]
2. Get the admin password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
3. Paste password → click "Install suggested plugins"
4. Create your admin user (username/password/email)
5. Confirm instance URL → Save and Finish
Quick theory recap
• Jenkins = open-source automation server for CI/CD
• Pipeline as Code = Jenkinsfile, version-controlled build steps
• 1500+ plugins; supports distributed builds across agents
Experiment 6 — Jenkins CI Pipeline + Git/Maven Integration
Step 1 — Push your Maven project to GitHub
git config --global [Link] "you@[Link]"
git config --global [Link] "Your Name"
cd HelloMaven # or your project folder
git init
git add [Link] src
git commit -m "first Maven project for Jenkins"
git remote add origin git@[Link]:yourusername/[Link]
git config --global [Link] true
git push origin main
SSH key needed once: ssh-keygen -t ed25519 -C "you@[Link]" then add the public key to GitHub → Settings
→ SSH keys.
Step 2 — Create Jenkins Pipeline job
1. Jenkins Dashboard → New Item
2. Name it e.g. Maven-CI → choose "Pipeline" → OK
3. Scroll to Pipeline section → choose "Pipeline script"
Step 3 — Paste this pipeline script
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: '[Link]
}
}
stage('Build') {
steps { sh 'mvn clean package' }
}
stage('Test') {
steps { sh 'mvn test' }
}
}
}
Step 4 — Save & Run
4. Tick "Use Groovy Sandbox" → Save
5. Jenkins Dashboard → click ▶ (play) on your pipeline
6. Click the build number → Console Output
✔ Expect to see: Stage view: Checkout → Build → Test all green, ends with "Finished: SUCCESS"
Optional — publish JUnit test reports
**/target/surefire-reports/*.xml
Add this pattern in Post-build Actions → "Publish JUnit test result report".
Experiment 7 — Ansible: Inventory, Playbook, Modules
Step 1 — Install Ansible
sudo apt update
sudo apt install ansible -y
ansible --version
Step 2 — Create inventory file
gedit [Link]
Content:
[local]
localhost ansible_connection=local
Step 3 — Write a basic playbook ([Link])
---
- name: Basic Server Setup
hosts: local
become: yes
tasks:
- name: Update apt cache
apt:
update_cache: yes
- name: Install curl
apt:
name: curl
state: present
Step 4 — Run it
ansible-playbook -i [Link] [Link]
✔ Expect to see: PLAY RECAP ... localhost : ok=2 changed=1 unreachable=0 failed=0
Key terms for viva
• Inventory = list of target machines ([Link])
• Playbook = YAML file of tasks (the "what to do")
• Module = the actual unit of work (apt, copy, service, template, user)
• Idempotent = running twice gives the same end state, no duplicate changes
• Agentless = works over SSH, no software needed on target machines
Experiment 8 — Jenkins CI + Ansible Deployment
Goal: Jenkins builds the Maven JAR → archives it → Ansible copies it to a target path automatically.
Step 1 — Prep a dummy target file (so size-change is visible)
gedit [Link] # type any character, save
ls -l /home/student/[Link]
Step 2 — Jenkins Pipeline job with Deploy stage
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git branch: 'main', url: '[Link]
}
}
stage('Build') {
steps { sh 'mvn clean package' }
}
stage('Test') {
steps { sh 'mvn test' }
}
stage('Archive Artifacts') {
steps {
archiveArtifacts artifacts: '**/target/*.jar', allowEmptyArchive: true
}
}
stage('Deploy') {
steps {
sh """
export ANSIBLE_HOST_KEY_CHECKING=False
ansible-playbook -i [Link] [Link] \
--extra-vars='ansible_become_pass=YOUR_PASSWORD'
"""
}
}
}
}
Step 3 — [Link] (place in Jenkins workspace folder)
---
- name: Deploy Artifact to Localhost
hosts: localhost
tasks:
- name: Copy the artifact to the target location
become: true
become_user: student
become_method: su
copy:
src: "/var/lib/jenkins/workspace/<job-name>/target/[Link]"
dest: "/home/student/[Link]"
Adjust paths: Replace <job-name> with your actual Jenkins job/workspace name, and the jar filename with
whatever mvn package actually produced (check target/ folder).
Step 4 — Run & verify
1. Jenkins → Build Now → Console Output
ls -l /home/student/[Link]
✔ Expect to see: Finished: SUCCESS, and [Link] now shows a LARGER file size than before deployment
Experiment 9 — Azure DevOps: Org & Project Setup
Step 1 — Create account & organization
1. Go to [Link] → Sign in with Microsoft account
2. Click "Create new organization" → pick a unique name + region
Step 2 — Create a project
3. On org dashboard → "New Project"
4. Enter Project Name (e.g. HelloDevOps)
5. Visibility: Private (default, recommended)
6. Click Create
What you'll see in the project
• Repos — Git source code hosting
• Pipelines — CI/CD automation
• Boards — Agile work tracking (sprints, backlog, Kanban)
• Test Plans — manage/run tests
• Artifacts — host Maven/npm/NuGet packages
Experiment 10 — Azure Build Pipeline (Maven + GitHub)
Step 1 — Use your existing GitHub Maven repo (Exp 6/8)
Step 2 — Create the pipeline
1. Azure DevOps → Pipelines → Create Pipeline
2. Choose GitHub (YAML) → select your repository
3. Authorize Azure Pipelines on GitHub if prompted
4. Choose "Maven" template → YAML auto-generated from [Link]
5. Click Save and Run → confirm commit → Run
✔ Expect to see: Job turns green, ends with Finalize Job / Success
Step 3 — Standard Maven + test-publish YAML
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Maven@3
inputs:
mavenPomFile: '[Link]'
goals: 'clean package'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/target/surefire-reports/TEST-*.xml'
mergeTestResults: true
testRunTitle: 'Maven Unit Test Results'
Step 4 — Verify
• Pipeline run page → stages: Checkout → Maven → (Publish Test Results)
• Click "Tests" tab → see pass/fail counts
If "no test results found": Check the testResultsFiles glob path actually matches where Surefire wrote XML
(target/surefire-reports/).
Experiment 11 — Azure Release Pipeline + Key Vault
Goal: Take the artifact from Exp 10's build pipeline and deploy it to an Azure App Service, while pulling secrets
from Key Vault instead of hardcoding them.
Prerequisites (set up once, ahead of time)
• Azure DevOps project with a working build pipeline (Exp 10)
• An Azure App Service already created to host the app
• An Azure Key Vault instance created for secrets (DB strings, API keys)
Step 1 — Create the Release Pipeline
1. Azure DevOps → Pipelines → Releases → New Pipeline
2. Choose template: "Azure App Service deployment"
3. Add an Artifact → select your build pipeline's output
4. In the Stage, set Azure subscription + App Service name
Step 2 — Link Azure Key Vault (so secrets aren't hardcoded)
5. Add a task: "Azure Key Vault" in the pipeline
6. Select your subscription + the Key Vault name
7. Pick which secrets to pull (or use a filter '*')
Why this matters: Secrets get pulled at pipeline run-time as variables, never stored in plain text in the
YAML/pipeline definition.
Step 3 — Trigger continuous deployment
8. Enable the "Continuous deployment trigger" on the artifact
9. Every successful build from Exp 10 now auto-deploys
10. Create Release → Deploy → watch the stage logs
✔ Expect to see: Stage status: Succeeded; app reachable at [Link]
CI vs CD — say this clearly in viva
• CI (Exp 10) = build + test automatically on every commit
• CD (Exp 11) = automatically deploy the build artifact to a live environment
• Key Vault = secure, centralized secret storage, pulled at runtime
One-Page Command Cheat Sheet
Maven
mvn archetype:generate -DgroupId=[Link] -DartifactId=App \
-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
mvn compile | mvn test | mvn package | mvn clean
Gradle
gradle init --type java-application
gradle build | gradle run | gradle <taskname>
Jenkins
sudo systemctl start jenkins
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
# Pipeline script stages: Checkout (git) -> Build (mvn) -> Test (mvn test)
Ansible
ansible --version
ansible-playbook -i [Link] <playbook>.yml
# [Link]: [local] localhost ansible_connection=local
Git (for Jenkins/Azure integration)
git init
git add . && git commit -m "message"
git remote add origin <repo-url>
git push origin main
Good luck for the exam tomorrow — walk through Experiments 6 and 8 twice; those tie Maven + Jenkins +
Ansible together and are the most likely combined practical question.