-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathJenkinsfile
168 lines (164 loc) · 5.62 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
166
167
168
pipeline {
agent any
environment {
JDK_TOOL_NAME = 'JDK 11'
MAVEN_TOOL_NAME = 'Maven 3.9.9'
}
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'
}
}
}
stage('Code Analysis') {
when {
anyOf {
branch 'main'
tag 'v*'
changeRequest()
}
}
options {
timeout(activity: true, time: 240, unit: 'SECONDS')
}
steps {
withMaven(jdk: env.JDK_TOOL_NAME, maven: env.MAVEN_TOOL_NAME) {
// `package` goal is required here to load modules in reactor and avoid dependency resolve conflicts
sh 'mvn -DskipTests=true package 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 'main'
tag 'v*'
changeRequest()
}
}
options {
timeout(activity: true, time: 180, 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'
}
}
}
stage('Integration Tests') {
when {
anyOf {
branch 'main'
tag 'v*'
changeRequest()
}
}
options {
timeout(activity: true, time: 600, 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 {
discoverReferenceBuild()
recordCoverage(tools: [[ parser: 'JACOCO' ]],
id: 'jacoco', name: 'JaCoCo Coverage',
sourceCodeRetention: 'LAST_BUILD')
}
}
}
stage('Deploy to Internal Nexus Repository') {
when {
anyOf {
branch 'main'
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('Make Github Release') {
when {
tag 'v*'
}
steps {
writeFile file: 'release_description.md', text: 'A new version of TLS-Scanner was released. You can download the artifacts (executable .jar) below. \n\n## Changelog:\n - TODO'
sh "zip -r TLS-Scanner-${TAG_NAME}.zip apps"
script {
def draftRelease = createGitHubRelease(
credentialId: '1522a497-e78a-47ee-aac5-70f071fa6714',
repository: GIT_URL.tokenize("/.")[-3,-2].join("/"),
draft: true,
tag: TAG_NAME,
name: TAG_NAME,
bodyFile: 'release_description.md',
commitish: GIT_COMMIT)
uploadGithubReleaseAsset(
credentialId: '1522a497-e78a-47ee-aac5-70f071fa6714',
repository: GIT_URL.tokenize("/.")[-3,-2].join("/"),
tagName: draftRelease.htmlUrl.tokenize("/")[-1],
uploadAssets: [
[filePath: "${env.WORKSPACE}/TLS-Scanner-${TAG_NAME}.zip"]
]
)
}
}
}
}
post {
always {
recordIssues enabledForFailure: true, tools: [mavenConsole(), java(), javaDoc()]
}
}
}