-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathJenkinsfile
executable file
·135 lines (134 loc) · 3.38 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
pipeline {
agent any
parameters {
choice(
name: 'TYPE',
choices: ['QUICK', 'FULL'],
description: 'Build types:<p>QUICK: Compile, Build, Deploy artifacts, Skip integration tests and extra artifacts, Multithread build<p>FULL: Compile, Build, Deploy artifacts, Run integration tests and extra artifacts, Singlethread build\n'
)
booleanParam(name: 'RELEASE', defaultValue: false, description: 'Make a Maven release')
booleanParam(name: 'DRY_RUN', defaultValue: false, description: 'Test run before release')
}
tools {
maven 'Maven 3.8.5'
jdk 'OpenJDK11'
}
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
skipStagesAfterUnstable()
timestamps()
disableConcurrentBuilds()
}
stages {
stage('Validate') {
when {
allOf {
expression { params.RELEASE }
not {
branch 'master'
}
}
}
steps {
script {
error('Releases are only allowed from the master branch.')
}
}
}
stage('Setup') {
steps {
script {
env.VERSION = """${sh(returnStdout: true, script: './build/get-version.sh ${RELEASE}')}"""
if (params.RELEASE) {
env.BUILD_TYPE = 'FULL'
} else {
env.BUILD_TYPE = params.TYPE
}
}
}
}
stage('Quick build') {
when {
expression {
env.BUILD_TYPE == 'QUICK'
}
}
steps {
sh 'mvn clean verify -U -T 3 -P skip-release-it'
}
}
stage('Full build') {
when {
expression {
env.BUILD_TYPE == 'FULL' && env.DRY_RUN == 'false'
}
}
steps {
sh 'mvn clean verify -U'
}
}
stage('Snapshots to nexus') {
environment {
PROFILES = getProfiles()
}
when {
expression {
env.RELEASE == 'false'
}
}
steps {
configFileProvider([configFile(fileId: 'org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig1387378707709', variable: 'MAVEN_SETTINGS')]) {
sh 'mvn -s $MAVEN_SETTINGS deploy -B -DskipTests -P ${PROFILES}'
}
}
}
stage('Release version to nexus') {
environment {
PROFILES = getProfiles()
}
when {
allOf {
expression { params.RELEASE }
branch 'master'
}
}
steps {
configFileProvider([configFile(fileId: 'org.jenkinsci.plugins.configfiles.maven.GlobalMavenSettingsConfig1387378707709', variable: 'MAVEN_SETTINGS')]) {
git 'https://github.com/gbif/pipelines.git'
sh 'mvn -s $MAVEN_SETTINGS release:prepare release:perform -Denforcer.skip=true -Dmaven.test.skip=true -P ${PROFILES}'
}
}
}
stage('Build and publish Docker image') {
when {
expression {
env.DRY_RUN == 'false'
}
}
steps {
sh 'build/ingestion-docker-build.sh ${RELEASE} ${VERSION}'
}
}
}
post {
success {
echo 'Pipeline executed successfully!'
}
failure {
echo 'Pipeline execution failed!'
}
cleanup {
deleteDir()
}
}
}
def getProfiles() {
def profiles = "skip-release-it,gbif-artifacts"
if (env.BUILD_TYPE == 'FULL') {
profiles += ",extra-artifacts"
}
if (env.DRY_RUN == 'true') {
profiles += " -DdryRun"
}
return profiles
}