-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
78 lines (70 loc) · 1.89 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
71
72
73
74
75
76
77
78
pipeline {
environment {
IMAGE_NAME = "numeric-webapp"
APP_CONTAINER_PORT = "8080"
DOCKERHUB_ID = "malikdevops97"
// DOCKERHUB_PASSWORD = credentials('dockerhub_password')
IMAGE_TAG = "latest"
}
agent any
stages {
stage('Build Artifacts') {
steps {
sh "mvn clean package -DskipTests=true"
archiveArtifacts artifacts: 'target/*.jar', fingerprint: true
}
}
stage('Unit Tests - JUnit and JaCoCo') {
steps {
sh "mvn test"
}
}
stage('Mutation Tests - PIT') {
steps {
sh "mvn org.pitest:pitest-maven:mutationCoverage"
}
}
stage('Build image') {
agent any
steps {
script {
sh 'docker build -t ${DOCKERHUB_ID}/$IMAGE_NAME:$IMAGE_TAG .'
}
}
}
stage('Run container based on builded image') {
agent any
steps {
script {
sh '''
echo "Cleaning existing container if exist"
docker ps -a | grep -i $IMAGE_NAME && docker rm -f ${IMAGE_NAME}
docker run --name ${IMAGE_NAME} -d -p 8010:$APP_CONTAINER_PORT ${DOCKERHUB_ID}/$IMAGE_NAME:$IMAGE_TAG
sleep 5
'''
}
}
}
stage('Test') {
steps {
script {
sh '''
echo "Testing the application"
curl -s http://localhost:8010/ | grep -i "200"
'''
}
}
}
stage('Clean container') {
agent any
steps {
script {
sh '''
docker stop $IMAGE_NAME
docker rm $IMAGE_NAME
'''
}
}
}
}
}