forked from schottsfired/sample-rest-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
88 lines (79 loc) · 1.76 KB
/
Jenkinsfile
File metadata and controls
88 lines (79 loc) · 1.76 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
library 'github.com/schottsfired/pipeline-libraries'
pipeline {
agent any
options {
timestamps()
buildDiscarder(logRotator(numToKeepStr:'10')) //delete old builds
}
environment {
DOCKERHUB = credentials('dockerhub')
IMAGE_NAME = "schottsfired/sample-rest-server"
IMAGE_TAG = dockerImageTag()
DOCKER_NETWORK = "cjt-network"
}
stages {
stage('Build, Unit, Package') {
steps {
sh 'mvn clean package'
junit testResults: '**/target/surefire-reports/TEST-*.xml'
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
stage('Create Docker Image') {
steps {
sh "docker build -t $IMAGE_NAME:$IMAGE_TAG ."
}
}
stage('Quality Analysis') {
steps {
parallel (
"Sonar Scan" : {
sh "mvn sonar:sonar -Dsonar.host.url=http://sonar:9000"
},
"Functional Test" : {
//fire up the app
sh """
docker run -d \
--name sample-rest-server \
--network $DOCKER_NETWORK \
-p 4567:4567 \
$IMAGE_NAME:$IMAGE_TAG
"""
//hit the /hello endpoint and collect result
retry(3) {
sleep 2
sh 'curl -v http://sample-rest-server:4567/hello > functionalTest.txt'
}
//store result
archiveArtifacts artifacts: 'functionalTest.txt', fingerprint: true
}, failFast: true
)
}
}
stage('Publish Docs') {
when {
branch 'master'
}
steps {
sh 'mvn site:site'
step([$class: 'JavadocArchiver', javadocDir: 'target/site/apidocs', keepAll: false])
}
}
stage('Push Docker Image') {
when {
branch 'master'
}
steps {
sh """
docker login -u $DOCKERHUB_USR -p $DOCKERHUB_PSW
docker push $IMAGE_NAME:$IMAGE_TAG
"""
}
}
}
post {
always {
dockerNuke(IMAGE_NAME, IMAGE_TAG)
}
}
}