-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJenkinsfile
More file actions
executable file
·116 lines (107 loc) · 3.05 KB
/
Jenkinsfile
File metadata and controls
executable file
·116 lines (107 loc) · 3.05 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
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
pipeline {
agent any
tools {
maven 'Maven 3.8.5'
jdk 'OpenJDK11'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
skipStagesAfterUnstable()
timestamps()
}
parameters {
separator(name: "release_separator", sectionHeader: "Release Project Parameters")
booleanParam(name: 'RELEASE', defaultValue: false, description: 'Do a Maven release')
string(name: 'RELEASE_VERSION', defaultValue: '', description: 'Release version (optional)')
string(name: 'DEVELOPMENT_VERSION', defaultValue: '', description: 'Development version (optional)')
booleanParam(name: 'DRY_RUN_RELEASE', defaultValue: false, description: 'Dry Run Maven release')
}
environment {
POM_VERSION = readMavenPom().getVersion()
}
stages {
stage('Validate') {
when {
allOf {
expression { params.RELEASE }
not {
branch 'master'
}
}
}
steps {
script {
error('Releases are only allowed from the master branch.')
}
}
}
stage('Maven build') {
when {
allOf {
not { expression { params.RELEASE } };
}
}
steps {
withMaven(traceability: true) {
configFileProvider([configFile(fileId: 'org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig1387378707709', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS clean verify deploy -B -U'
}
}
}
}
stage('Maven release: Main project') {
when {
allOf {
expression { params.RELEASE };
branch 'master';
}
}
environment {
RELEASE_ARGS = createReleaseArgs(params.RELEASE_VERSION, params.DEVELOPMENT_VERSION, params.DRY_RUN_RELEASE)
}
steps {
configFileProvider(
[configFile(fileId: 'org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig1387378707709',
variable: 'MAVEN_SETTINGS_XML')]) {
git 'https://github.com/gbif/key-value-store.git'
sh 'mvn -s $MAVEN_SETTINGS_XML -B -Denforcer.skip=true release:prepare release:perform $RELEASE_ARGS'
}
}
}
stage('Build and push Docker image') {
environment {
VERSION = getDockerVersion()
}
steps {
sh 'build/kvs-indexing-docker-build.sh ${VERSION}'
}
}
}
post {
success {
echo 'KVS executed successfully!'
}
failure {
echo 'KVS execution failed!'
}
}
}
def createReleaseArgs(inputVersion, inputDevVersion, inputDryrun) {
def args = ""
if (inputVersion != '') {
args += " -DreleaseVersion=" + inputVersion
}
if (inputDevVersion != '') {
args += " -DdevelopmentVersion=" + inputDevVersion
}
if (inputDryrun) {
args += " -DdryRun=true"
}
return args
}
def getDockerVersion() {
if (params.RELEASE && params.RELEASE_VERSION != '') {
return inputVersion
}
return "${POM_VERSION}"
}