forked from Pretronic/PretronicDatabaseQuery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJenkinsfile
More file actions
178 lines (156 loc) · 7.04 KB
/
Jenkinsfile
File metadata and controls
178 lines (156 loc) · 7.04 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
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
169
170
171
172
173
174
175
176
177
178
final String CI_NAME = "PretronicCI"
final String CI_EMAIL = "ci@pretronic.net"
final String COMMIT_MESSAGE = "Version change %version%"
final String BRANCH_DEVELOPMENT = "origin/development"
final String BRANCH_MASTER = "origin/master"
final String PROJECT_SSH = "git@github.com:Pretronic/PretronicDatabaseQuery.git"
final String PROJECT_NAME = "PretronicDatabaseQuery"
String VERSION = "UNDEFINED"
String BRANCH = "UNDEFINED"
boolean SKIP = false
int BUILD_NUMBER = -1;
pipeline {
agent any
tools {
maven 'Maven3'
jdk 'Java9'
}
options {
buildDiscarder logRotator(numToKeepStr: '10')
}
stages {
stage('CI Check') {
steps {
script {
String name = sh script: 'git log -1 --pretty=format:\"%an\"', returnStdout: true
String email = sh script: 'git log -1 --pretty=format:\"%ae\"', returnStdout: true
if (name == CI_NAME && email == CI_EMAIL) {
SKIP = true;
}
}
}
}
stage('Read information') {
when { equals expected: false, actual: SKIP }
steps {
script {
VERSION = readMavenPom().getVersion()
BRANCH = env.GIT_BRANCH
BUILD_NUMBER = env.BUILD_NUMBER.toInteger()
}
}
}
stage('Version change') {
when { equals expected: false, actual: SKIP }
steps {
script {
String[] versionSplit = VERSION.split("[-.]")
String major = versionSplit[0]
int minorVersion = versionSplit[1].toInteger()
int patchVersion = versionSplit[2].toInteger()
VERSION = major + "." + minorVersion + "." + patchVersion + "." + BUILD_NUMBER
if (BRANCH.equalsIgnoreCase(BRANCH_DEVELOPMENT)) {
if (!VERSION.endsWith("-SNAPSHOT")) {
VERSION = VERSION + '-SNAPSHOT'
}
}
sh "mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$VERSION"
}
}
}
stage('Build & Deploy') {
when { equals expected: false, actual: SKIP }
steps {
configFileProvider([configFile(fileId: 'afe25550-309e-40c1-80ad-59da7989fb4e', variable: 'MAVEN_GLOBAL_SETTINGS')]) {
sh 'mvn -B -gs $MAVEN_GLOBAL_SETTINGS clean deploy'
}
}
}
stage('Publish javadoc') {
when { equals expected: false, actual: SKIP }
steps {
script {
if(BRANCH == BRANCH_MASTER) {
sh 'mvn javadoc:aggregate-jar'
withCredentials([string(credentialsId: '120a9a64-81a7-4557-80bf-161e3ab8b976', variable: 'SECRET')]) {
String name = env.JOB_NAME
httpRequest(acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_OCTETSTREAM',
httpMode: 'POST', ignoreSslErrors: true, timeout: 3000,
multipartName: 'file',
responseHandle: 'NONE',
uploadFile: "target/${name}-${VERSION}-javadoc.jar",
customHeaders:[[name:'token', value:"${SECRET}", maskValue:true]],
url: "https://pretronic.net/javadoc/${name}/${VERSION}/create")
}
}
}
}
}
stage('Archive') {
when { equals expected: false, actual: SKIP }
steps {
archiveArtifacts artifacts: '**/target/*.jar'
}
}
}
post {
success {
script {
if(!SKIP) {
sh """
git config --global user.name '$CI_NAME' -v
git config --global user.email '$CI_EMAIL' -v
"""
String[] versionSplit = VERSION.split("[-.]")
String major = versionSplit[0]
int minorVersion = versionSplit[1].toInteger()
int patchVersion = versionSplit[2].toInteger()
if (BRANCH == BRANCH_DEVELOPMENT) {
patchVersion++
BUILD_NUMBER++
String version = major + "." + minorVersion + "." + patchVersion+ "." + BUILD_NUMBER + "-SNAPSHOT"
String commitMessage = COMMIT_MESSAGE.replace("%version%", version)
sh """
mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$version
git add . -v
git commit -m '$commitMessage' -v
"""
sshagent(['1c1bd183-26c9-48aa-94ab-3fe4f0bb39ae']) {
sh "git push origin HEAD:development -v"
}
} else if (BRANCH == BRANCH_MASTER) {
String version = major + "." + minorVersion + "." + patchVersion + "." + BUILD_NUMBER
String commitMessage = COMMIT_MESSAGE.replace("%version%", version)
sshagent(['1c1bd183-26c9-48aa-94ab-3fe4f0bb39ae']) {
sh """
mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$version
git add . -v
git commit -m '$commitMessage' -v
git push origin HEAD:master -v
"""
BUILD_NUMBER++
minorVersion++
patchVersion = 0
version = major + "." + minorVersion + "." + patchVersion + "." + BUILD_NUMBER + "-SNAPSHOT"
commitMessage = COMMIT_MESSAGE.replace("%version%", version)
sh """
if [ -d "tempDevelopment" ]; then rm -Rf tempDevelopment; fi
mkdir tempDevelopment
cd tempDevelopment/
git clone --single-branch --branch development $PROJECT_SSH
cd $PROJECT_NAME/
mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$version
git add . -v
git commit -m '$commitMessage' -v
git push origin HEAD:development -v
cd ..
cd ..
if [ -d "tempDevelopment" ]; then rm -Rf tempDevelopment; fi
"""
}
}
}
}
}
}
}