forked from gbif/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
162 lines (159 loc) · 4.68 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
pipeline {
agent any
tools {
maven 'Maven3.6'
jdk 'JDK8'
}
options {
buildDiscarder(logRotator(numToKeepStr: '4'))
timestamps ()
}
parameters {
booleanParam(name: 'DOCUMENTATION',
defaultValue: false,
description: 'Generate API documentation')
separator(name: "release_separator", sectionHeader: "Release Parameters")
booleanParam(name: 'RELEASE',
defaultValue: false,
description: 'Do a Maven release (it also generates API documentation)')
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')
}
stages {
stage('Preconditions') {
steps {
scmSkip(skipPattern:'.*(\\[maven-release-plugin\\] prepare release |Generated API documentation|Google Java Format).*')
}
}
stage('Build') {
when {
allOf {
not { expression { params.RELEASE } };
not { expression { params.DOCUMENTATION } };
}
}
steps {
withMaven(maven: 'Maven3.6') {
sh 'mvn clean package install -T 2C -e -DskipTests -DskipITs -Ddocker.skip.run'
}
}
}
stage('Tests') {
when {
allOf {
not { expression { params.RELEASE } };
not { expression { params.DOCUMENTATION } };
}
}
failFast true
parallel {
stage('Unit tests') {
steps {
withMaven(maven: 'Maven3.6') {
sh 'mvn surefire:test -T 2C -Dparallel=classes -DuseUnlimitedThreads=true -e -Pcoverage -Ddocker.skip.run -DskipITs'
}
}
}
stage('Integration tests') {
environment {
ALANM_PORT = findFreePort()
ALANM_ADMIN_PORT = findFreePort()
ALA_SOLR_PORT = findFreePort()
SDS_ADMIN_PORT = findFreePort()
SDS_PORT = findFreePort()
}
steps {
withMaven(maven: 'Maven3.6') {
//Zookeeper port is SOLR_PORT + 1000
sh 'mvn resources:testResources docker:build docker:start failsafe:integration-test docker:stop -e -T 1C -Pcoverage -Dalanm.port=$ALANM_PORT -Dalanm.admin.port=$ALANM_ADMIN_PORT -Dsolr8.zk.port=$(($ALA_SOLR_PORT+1000)) -Dsolr8.http.port=$ALA_SOLR_PORT -Dsds.admin.port=$SDS_ADMIN_PORT -Dsds.port=$SDS_PORT'
}
}
}
}
}
stage('SonarQube analysis') {
when {
allOf {
not { expression { params.RELEASE } };
not { expression { params.DOCUMENTATION } };
branch 'dev';
}
}
steps {
withSonarQubeEnv('GBIF Sonarqube') {
withMaven(maven: 'Maven3.6', mavenSettingsConfig: 'org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig1387378707709') {
sh 'mvn jacoco:prepare-agent jacoco:report sonar:sonar -DskipITs'
}
}
}
}
stage('Snapshot to nexus') {
when {
allOf {
not { expression { params.RELEASE } };
not { expression { params.DOCUMENTATION } };
branch 'dev';
}
}
steps {
withMaven(maven: 'Maven3.6', mavenSettingsConfig: 'org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig1387378707709') {
sh 'mvn -DskipTests deploy'
}
}
}
stage('Release version to nexus') {
when {
allOf {
expression { params.RELEASE };
branch 'master';
}
}
environment {
RELEASE_ARGS = createReleaseArgs()
}
steps {
withMaven(maven: 'Maven3.6') {
sh 'mvn -B release:prepare release:perform $RELEASE_ARGS'
}
}
}
}
post {
failure {
slackSend message: "Pipelines build failed! - ${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)",
channel: "#dev"
}
always {
junit '**/target/failsafe-reports/*.xml'
}
}
}
/**
* Finds a free tcp port.
*/
int findFreePort(){
new ServerSocket(0).with { socket ->
try {
return socket.getLocalPort()
} finally {
socket.close()
}
}
}
/**
* Creates the Maven release arguments based on the pipeline parameters.
*/
def createReleaseArgs() {
def args = ""
if (params.RELEASE_VERSION != '') {
args += "-DreleaseVersion=${params.RELEASE_VERSION} "
}
if (params.DEVELOPMENT_VERSION != '') {
args += "-DdevelopmentVersion=${params.DEVELOPMENT_VERSION} "
}
if (params.DRY_RUN_RELEASE) {
args += "-DdryRun=true"
}
return args
}