-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsFile
70 lines (62 loc) · 1.8 KB
/
JenkinsFile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pipeline {
agent {
docker {
image 'maven:3.9.6-eclipse-temurin-21' // Maven 3.9.6 with JDK 21
args '--user root -v /var/run/docker.sock:/var/run/docker.sock'
}
}
stages {
stage('Checkout') {
steps {
// Clone the repository
git url: 'https://github.com/rahulcse1/DataStructure.git', branch: 'master'
}
}
stage('Install Dependencies') {
steps {
sh 'mvn clean install -DskipTests' // Install dependencies without running tests yet
}
}
stage('Build') {
steps {
sh 'mvn package' // Builds the Spring Boot JAR/WAR
}
}
stage('Test') {
steps {
sh 'mvn test' // Runs unit/integration tests
}
post {
always {
junit '**/target/surefire-reports/*.xml' // Publishes test results
}
}
}
stage('Deploy') {
when {
branch 'master' // Only deploy from main branch
}
steps {
sh '''
echo "Deploying Spring Boot application..."
# Example: Copy JAR to a server or run it
# java -jar target/*.jar
'''
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
archiveArtifacts artifacts: 'target/*.jar', allowEmptyArchive: true // Archive the built JAR
}
failure {
echo 'Pipeline failed. Check the logs for details.'
}
always {
node('') {
cleanWs()
}
}
}
}