-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
74 lines (68 loc) · 2.47 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
import java.util.regex.Matcher
node {
catchError {
def version
docker.image('silverpeas/silverbuild')
.inside('-v $HOME/.m2:/home/silverbuild/.m2 -v $HOME/.gitconfig:/home/silverbuild/.gitconfig -v $HOME/.ssh:/home/silverbuild/.ssh -v $HOME/.gnupg:/home/silverbuild/.gnupg') {
stage('Preparation') {
checkout scm
version = computeSnapshotVersion()
sh """
mvn -U versions:set -DgenerateBackupPoms=false -DnewVersion=${version}
"""
}
stage('Build') {
def lockFilePath = createLockFile(version, 'testdep')
def status = sh (returnStatus: true,
script: "mvn clean install -Djava.awt.headless=true")
deleteLockFile(lockFilePath)
if (status != 0) {
error "Build Failure"
}
}
}
}
step([$class : 'Mailer',
notifyEveryUnstableBuild: true,
sendToIndividuals : true])
}
def computeSnapshotVersion() {
def pom = readMavenPom()
final String version = pom.version
final String release = pom.properties['next.release']
final String defaultVersion = env.BRANCH_NAME == 'master' || env.BRANCH_NAME.endsWith('.x') ?
version : release + '-' + env.BRANCH_NAME.toLowerCase().replaceAll('[# -]', '')
Matcher m = env.CHANGE_TITLE =~ /^(Bug #?\d+|Feature #?\d+).*$/
String snapshot = m.matches()
? m.group(1).toLowerCase().replaceAll(' #?', '')
: ''
if (snapshot.isEmpty()) {
m = env.CHANGE_TITLE =~ /^\[([^\[\]]+)].*$/
snapshot = m.matches()
? m.group(1).toLowerCase().replaceAll('[/><|:&?!;,*%$=}{#~\'"\\\\°)(\\[\\]]', '').trim().replaceAll('[ @]', '-')
: ''
}
return snapshot.isEmpty() ? defaultVersion : "${release}-${snapshot}"
}
static def createLockFilePath(version, projectName) {
final String lockFilePath = "\$HOME/.m2/${version}_${projectName}_build.lock"
return lockFilePath
}
def createLockFile(version, projectName) {
final String lockFilePath = createLockFilePath(version, projectName)
sh "touch ${lockFilePath}"
return lockFilePath
}
def deleteLockFile(lockFilePath) {
if (isLockFileExisting(lockFilePath)) {
sh "rm -f ${lockFilePath}"
}
}
def isLockFileExisting(lockFilePath) {
if (lockFilePath?.trim()?.length() > 0) {
def exitCode = sh script: "test -e ${lockFilePath}", returnStatus: true
return exitCode == 0
}
return false
}