-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
165 lines (159 loc) · 5.44 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
pipeline {
agent any
environment {
JDK_TOOL_NAME = 'JDK 11'
MAVEN_TOOL_NAME = 'Maven 3.8.6'
}
options {
skipStagesAfterUnstable()
disableConcurrentBuilds abortPrevious: true
}
stages {
stage('Clean') {
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
sh 'mvn clean'
}
}
}
stage('Format Check') {
options {
timeout(activity: true, time: 60, unit: 'SECONDS')
}
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
sh 'mvn spotless:check'
}
}
}
stage('Build') {
options {
timeout(activity: true, time: 120, unit: 'SECONDS')
}
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
sh 'mvn -DskipTests=true package'
}
}
post {
success {
archiveArtifacts artifacts: '**/target/*.jar'
stash name: 'jar', includes: '**/apps/*.jar'
stash name: 'lib', includes: '**/apps/*.jar'
}
}
}
stage('Code Analysis') {
when {
anyOf {
branch 'master'
tag 'v*'
changeRequest()
}
}
options {
timeout(activity: true, time: 120, unit: 'SECONDS')
}
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
sh 'mvn pmd:pmd pmd:cpd spotbugs:spotbugs'
}
}
post {
always {
recordIssues enabledForFailure: true, tools: [spotBugs(), cpd(pattern: '**/target/cpd.xml'), pmdParser(pattern: '**/target/pmd.xml')]
}
}
}
stage('Unit Tests') {
when {
anyOf {
branch 'master'
tag 'v*'
changeRequest()
}
}
options {
timeout(activity: true, time: 120, unit: 'SECONDS')
}
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
sh 'mvn -P coverage -Dskip.failsafe.tests=true test'
}
}
post {
always {
junit testResults: '**/target/surefire-reports/TEST-*.xml', allowEmptyResults: true
}
}
}
stage('Integration Tests') {
when {
anyOf {
branch 'master'
tag 'v*'
changeRequest()
}
}
options {
timeout(activity: true, time: 120, unit: 'SECONDS')
}
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
sh 'mvn -P coverage -Dskip.surefire.tests=true verify'
}
}
post {
always {
junit testResults: '**/target/failsafe-reports/TEST-*.xml', allowEmptyResults: true
}
success {
publishCoverage adapters: [jacoco(mergeToOneReport: true, path: '**/target/site/jacoco/jacoco.xml')]
}
}
}
stage('Deploy Jar to Internal Nexus Repository') {
when {
anyOf {
branch 'master'
tag 'v*'
}
}
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
// Tests were already executed separately, so disable tests within this step
sh 'mvn -DskipTests=true deploy'
}
}
}
stage('Build & Deploy Docker Image to Internal Nexus Repository') {
when {
anyOf {
branch 'master'
tag 'v*'
}
}
environment {
DOCKER_PUSH = credentials('Jenkins-User-Nexus-Repository')
DOCKER_PUSH_URL = 'hydrogen.cloud.nds.rub.de'
}
steps {
unstash 'jar'
unstash 'lib'
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
sh 'mvn dependency:get -Dartifact=co.elastic.apm:elastic-apm-agent:1.38.0'
sh 'mvn dependency:copy -Dartifact=co.elastic.apm:elastic-apm-agent:1.38.0 -DoutputDirectory=.'
}
sh 'docker build -f ci.Dockerfile -t ${DOCKER_PUSH_URL}/tls-crawler:latest -t ${DOCKER_PUSH_URL}/tls-crawler:${BUILD_TIMESTAMP}_${BUILD_NUMBER} .'
sh 'docker login -u $DOCKER_PUSH_USR -p $DOCKER_PUSH_PSW $DOCKER_PUSH_URL'
sh 'docker push ${DOCKER_PUSH_URL}/tls-crawler:latest'
sh 'docker push ${DOCKER_PUSH_URL}/tls-crawler:${BUILD_TIMESTAMP}_${BUILD_NUMBER}'
}
}
}
post {
always {
recordIssues enabledForFailure: true, tools: [mavenConsole(), java(), javaDoc()]
}
}
}