-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
102 lines (100 loc) · 3.18 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
#!/usr/bin/env groovy
pipeline {
agent {
docker {
image 'maven:3.6-jdk-11-slim'
// Add configuration for Nexus repositories and user/group mapping for uid:gid of 1000:1000
args "-v ${env.JENKINS_HOME}/.m2/settings.xml:/tmp/settings.xml:ro -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro"
}
}
triggers {
// Empty string, to allow post-commit hook to notify Jenkins
pollSCM ''
}
options {
// LogRotator will keep the 20 most recents jobs and retain the artifacts only for the 2 latest
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '2'))
}
parameters {
string(name: 'MAVEN_OPTIONS', defaultValue: '', description: 'Optional parameters to be added to the mvn command line')
booleanParam(name: 'FORCE_DEPLOY', defaultValue: false, description: 'Force the execution of the deploy stage')
}
environment {
MAVEN_GLOBAL_OPTIONS = "-Duser.home=${env.WORKSPACE} -s /tmp/settings.xml --batch-mode --errors -Pdelivery"
}
stages {
stage('Compile') {
environment {
MAVEN_OPTIONS = "${env.MAVEN_GLOBAL_OPTIONS} -U ${params.MAVEN_OPTIONS}"
}
steps {
// Print disk space
sh 'df -h $WORKSPACE'
// Run the maven build (mvn is in the PATH of the Docker image)
sh 'mvn $MAVEN_OPTIONS clean compile'
}
}
stage('Test') {
// Do not run the tests when performing the release on master, they should have run earlier
when {
not { branch 'master' }
}
environment {
MAVEN_OPTIONS = "${env.MAVEN_GLOBAL_OPTIONS} -PskipCompilePlugins ${params.MAVEN_OPTIONS}"
}
steps {
sh 'mvn $MAVEN_OPTIONS test'
}
}
stage('Package') {
environment {
MAVEN_OPTIONS = "${env.MAVEN_GLOBAL_OPTIONS} -PskipCompilePlugins,skipTestPlugins ${params.MAVEN_OPTIONS}"
}
steps {
sh 'mvn $MAVEN_OPTIONS package'
}
}
stage('Deploy') {
when {
anyOf {
branch 'master'
branch 'dev'
buildingTag()
expression { params.FORCE_DEPLOY }
}
}
environment {
MAVEN_OPTIONS = "${env.MAVEN_GLOBAL_OPTIONS} -PskipCompilePlugins,skipTestPlugins ${params.MAVEN_OPTIONS}"
}
steps {
sh 'mvn $MAVEN_OPTIONS deploy'
}
}
}
post {
always {
junit testResults: '**/target/surefire-reports/TEST-*.xml', allowEmptyResults: true
recordIssues(
enabledForFailure: true, aggregatingResults: true,
tools: [
mavenConsole(),
java(),
checkStyle(pattern: '**/target/checkstyle-result.xml', reportEncoding: 'UTF-8'),
pmdParser(pattern: '**/target/pmd.xml'),
spotBugs(pattern: '**/target/spotbugsXml.xml')
]
)
publishCoverage(
adapters: [jacocoAdapter('**/target/site/jacoco/jacoco.xml')],
sourceFileResolver: sourceFiles('STORE_ALL_BUILD')
)
}
success {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
archiveArtifacts artifacts: '**/target/*.amp', fingerprint: true, allowEmptyArchive: true
}
cleanup {
sh 'mvn $MAVEN_GLOBAL_OPTIONS --quiet clean'
}
}
}