mvn archetype:generate -DgroupId=com.example -DartifactId=myapp -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
package com.example; public class App {
public static void main(String[] args) {
System.out.println("Hello, Maven");
System.out.println("This is the simple realworld example....");
int a = 5;
int b = 10;
System.out.println("Sum of " + a + " and " + b + " is " + sum(a, b));
}
public static int sum(int x, int y) {
return x + y; }
}
package com.example;
import org.junit.Assert;
import org.junit.Test;
public class AppTest {
@Test
public void testAdd() {
App app = new App();
int result = app.add(2, 3);
System.out.println("Running test: 2 + 3 = " + result);
Assert.assertEquals(5, result);
}
}
mvn compile
mvn test
mvn package
java -cp target/myapp-1.0-SNAPSHOT.jar com.example.App
gradle init --type java-application
plugins {
kotlin("jvm") version "1.8.21"
application
}
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
testImplementation("junit:junit:4.13.2")
}
application {
mainClass.set("com.example.MainKt")
}
tasks.test {
useJUnit()
testLogging {
events("passed", "failed", "skipped")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showStandardStreams = true
}
outputs.upToDateWhen { false }
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
package com.example
fun addNumbers(num1: Double, num2: Double): Double {
return num1 + num2
}
fun main() {
val num1 = 10.0
val num2 = 5.0
val result = addNumbers(num1, num2)
println("The sum of $num1 and $num2 is: $result")
}
gradle build
gradle test
gradle run
application {
mainClass.set("com.example.App")
}
✅ Step 1: Install and Set Up Jenkins
Download Jenkins: https://www.jenkins.io/download/
Run the Jenkins installer.
Access Jenkins: http://localhost:8080
Unlock Jenkins using the initial admin password (from the path shown during setup).
Install suggested plugins.
Create an admin user and complete the setup.
✅ Step 2: Install Required Jenkins Plugins
Go to Manage Jenkins > Manage Plugins, and install:
Git Plugin
Maven Integration Plugin
Gradle Plugin (only if using Gradle)
JUnit Plugin (for running tests)
✅ Step 3: Configure Global Tools
Go to Manage Jenkins > Global Tool Configuration:
🔹 JDK
Click Add JDK
Name: JDK17
Uncheck "Install automatically"
Enter JAVA_HOME manually (e.g., C:\Program Files\Java\jdk-17)
🔹 Maven
Click Add Maven
Name: Maven3
Uncheck "Install automatically"
Set path: C:\Program Files\Apache\Maven\bin
🔹 Gradle (if used)
Click Add Gradle
Name: Gradle7
Uncheck "Install automatically"
Set path: C:\Gradle\bin
✅ Step 5: Push Project to GitHub
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/your-username/ci-example.git
git push -u origin main
✅ Step 6: Create a Jenkins Job (Freestyle)
-
Go to Jenkins Dashboard → New Item
-
Enter a name (e.g.,
CI-Build
) → Select Freestyle project -
Under Source Code Management, choose Git
-
Repository URL:
https://github.com/your-username/ci-example.git
-
-
Under Build Triggers, enable Poll SCM (e.g.,
H/5 * * * *
) -
Under Build, choose:
-
Invoke top-level Maven targets
-
Goals:
clean install
-
(Or
gradle build
if using Gradle)
-
-
✅ Step 7: Run and Verify the Pipeline
-
Click Build Now.
-
Wait for the console output.
-
You should see:
-
Project is cloned from Git
-
Build steps executed (compile + test)
-
Test report summary in Jenkins
-
sudo apt update
sudo apt upgrade -y
sudo apt install software-properties-common -y
sudo add-apt-repository --yes --update ppa:ansible/ansible
sudo apt install ansible -y
ansible --version
sudo vi inventory.ini
[local]
localhost ansible_connection=local
sudo vi HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
sudo vi run-java.yml
- name: Compile and run HelloWorld.java in current directory
hosts: localhost
connection: local
tasks:
- name: Compile HelloWorld.java
shell: javac HelloWorld.java
args:
chdir: "{{ playbook_dir }}"
- name: Run HelloWorld
shell: java HelloWorld
args:
chdir: "{{ playbook_dir }}"
register: output
- name: Display output
debug:
msg: "{{ output.stdout }}"
ansible-playbook -i inventory.ini run-java.yml
pipeline {
agent any
tools {
maven 'Apache Maven 3.9.9'
}
stages {
stage('Build') {
steps {
dir('C:/path/to/your/local/project') {
bat 'mvn clean install'
}
}
}
stage('Archive Artifacts') {
steps {
archiveArtifacts artifacts: 'C:/path/to/your/local/project/target/*.jar', allowEmptyArchive: true
}
}
}
}
sudo apt install ansible -y
ansible --version
sudo vi hosts.ini
[local]
localhost ansible_connection=local
sudo vi deploy.yml
- name: Deploy artifact locally
hosts: localhost
connection: local
tasks:
- name: Copy JAR file from Jenkins to deploy directory
copy:
src: /home/ubuntu/Downloads/demo-1.0-SNAPSHOT.jar
dest: /home/ubuntu/Downloads/dest
ansible-playbook -i hosts.ini deploy.yml
ls
LAB PROGRAM-08 (PART A)
1. mvn archetype:generate -DgroupId=com.example -DartifactId=demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
2. cd demo
3. git init
4. git add .
5. git commit -m "Initial commit"
6. Go to your github account create one repository name “program8”
7. (On your github account you’ll get one url) copy and paste this command from there-
git remote add origin <your-repo-url>
8. git push -u origin main
{ if error comes the check
a) git status
If it shows you are in master branch ,change it to main by using command
b) git branch -M main
c) git push -u origin main }
9. Open jenkins (in your browser run this - http://localhost:8080)
If this does not run directly on your browser then,
Go to command prompt (open in administrator)
Type- java -jar (path of jenkin.war from your c drive)
10. Open jenkins provide your username and password
Go to dashboard :
a) Click on new item
b) Enter a project name (MavenCI)
c) Select “Pipeline” Click OK
d) Scroll Down to the Pipeline Section
e) Set the Definition to Pipeline Script
f) Inside that box, put this code-
pipeline {
agent any
tools {
maven 'Apache Maven 3.9.9'
}
stages {
stage('Checkout') {
steps {
git branch: 'main', url: 'https://github.com/Shashi8066/prgm08.git'
}
}
stage('Build') {
steps {
bat 'mvn clean install'
}
}
stage('Archive Artifacts') {
steps {
archiveArtifacts artifacts: 'target/*.jar', allowEmptyArchive: true
}
}
}
}
g) Click Save (at the bottom)
h) Click Build Now
i) Console Output. (it should show Finished: SUCCESS)
PART-B
Open ubuntu
1. vi hosts.ini
Inside that write code -
[local]
localhost ansible_connection=local
2. Vi deploy.yml
Inside that write code -
- name: Deploy artifact locally
hosts: local
tasks:
- name: Copy JAR file from Jenkins to deploy directory
copy:
src:/mnt/c/Users/ASUS/.jenkins/workspace/mavenCI/target/demo-1.0-SNAPSHOT.jar
dest: /mnt/c/Users/ASUS/deployed/demo-1.0-SNAPSHOT.jar
To find the source and destination -
- Open Jenkins.
- Go to your Maven job → Build History → Workspace.
- Navigate to the target/ folder and confirm the JAR file exists
- then in the src path provide your project name which you have given in your jenkins project (example-mavenCI)
- Go to your system directory (example=asus) and create a folder named deployed manually if it does not exist.
copy the demo-1.0-SNAPSHOT.jar file into it.
/mnt/ is used because the forward slash does not work in the unix system
3. ansible-playbook -i hosts.ini deploy.yml
4. To check whether it exists, run:
ls /mnt/c/Users/ASUS/deployed
It should give:
demo-1.0-SNAPSHOT.jar
LAB PROGRAM -09
Step 1: Create a Microsoft Account (if you don’t have one)
1. Open Safari or any browser.
2. Go to: https://signup.live.com
3. Sign up for a Microsoft account.
Step 2: Sign Up for Azure DevOps
1. Open browser and go to: https://dev.azure.com
2. Click "Start Free" or "Sign in".
3. Use your Microsoft account to log in
Step 3: Create an Azure DevOps Organization
1. After signing in, it will ask you to create an organization.
If you are not able to find create organization then click on this link below, it will directly take you to create organization page
https://aex.dev.azure.com/me
2. Give a name for your org (e.g., ksakshi33333).
3. Choose region (you can select the default).
4. Click Continue.
Step 4: Create a Project
1. Click on "New Project".
2. Enter:
○ Project name (e.g., MyFirstProject)
○ Visibility: Choose Private or Public.
3. Click Create.
Now your Azure DevOps Project is ready!