forked from yli202/JacocoExample
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
116 lines (96 loc) · 2.73 KB
/
Jenkinsfile
File metadata and controls
116 lines (96 loc) · 2.73 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
pipeline {
agent any
tools {
maven 'Maven'
dockerTool 'Docker'
}
parameters {
string(
name: 'BRANCH_NAME',
defaultValue: 'master',
description: 'Enter the Git branch to build'
)
}
environment {
APP_NAME = "week6demo-app"
DOCKER_IMAGE = "myrepo/week6demo-app:latest"
}
stages {
stage('Checkout') {
steps {
echo "Checking out source code..."
echo "Checking out source code from branch: ${params.BRANCH_NAME}"
git branch: "${params.BRANCH_NAME}",
url: 'https://github.com/billchen247/JacocoExample'
}
}
stage('Build') {
steps {
echo "Compiling source code..."
sh 'mvn clean compile'
}
}
stage('Unit Test') {
steps {
echo "Running unit tests..."
sh 'mvn test'
}
post {
always {
junit 'target/surefire-reports/*.xml'
}
}
}
stage('Code Coverage (JaCoCo)') {
steps {
echo "Generating JaCoCo coverage report..."
sh 'mvn jacoco:report'
}
}
stage('Publish Coverage') {
steps {
jacoco(
execPattern: 'target/jacoco.exec',
classPattern: 'target/classes',
sourcePattern: 'src/main/java'
)
}
}
stage('Package') {
steps {
echo "Packaging application..."
sh 'mvn package -DskipTests'
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
}
// ------------------------
// MOCK CD SECTION
// ------------------------
stage('Build Docker Image') {
when { branch 'master' }
steps {
echo "Building Docker image..."
sh "docker build -t ${DOCKER_IMAGE} ."
}
}
stage('Push Docker Image (Mock)') {
when { branch 'master' }
steps {
echo "Mock pushing Docker image..."
echo "docker push ${DOCKER_IMAGE}"
}
}
stage('Deploy to Dev (Mock)') {
when { branch 'master' }
steps {
echo "Mock deploy to Kubernetes..."
echo "kubectl apply -f k8s/deployment.yaml"
}
}
stage('Cleanup') {
steps {
cleanWs()
}
}
}
}