forked from checkstyle/checkstyle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
93 lines (74 loc) · 2.1 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
// Node label that specifies on which slave(s) the job should run
BUILD_SLAVES_LABEL = 'build-servers'
// 'sha1' envvar is injected by Jenkins GHPRB plugin in case if build is started by pull request
IS_TRIGGERED_BY_PR = env.sha1?.trim()
GIT_BRANCH = '<unknown>'
// Text colours definition
def GREEN( String msg ) { return "\u001B[32m${msg}\u001B[0m" }
def YELLOW( String msg ) { return "\u001B[33m${msg}\u001B[0m" }
def RED( String msg ) { return "\u001B[31m${msg}\u001B[0m" }
def getCause(def build) {
while(build.previousBuild) {
build = build.previousBuild
}
return build.rawBuild.getCause(hudson.model.Cause$UserIdCause)
}
def getCauseDescription(def build) {
return getCause(build).shortDescription
}
pipeline {
agent {
label "${BUILD_SLAVES_LABEL}"
}
options {
ansiColor('xterm')
}
stages {
stage ("Initial") {
steps {
echo GREEN("${getCauseDescription(currentBuild)}")
script {
// If build is triggered by PR, use PR branch, otherwise use master
if (IS_TRIGGERED_BY_PR) {
GIT_BRANCH = env.sha1
} else {
GIT_BRANCH = 'master'
}
}
echo GREEN("Branch: $GIT_BRANCH")
// Debug: print all the build envvars
// echo sh(returnStdout: true, script: 'env')
sh "mvn --version"
}
}
stage ("Prepare (triggered by PR)") {
when { expression { IS_TRIGGERED_BY_PR } }
steps {
echo "${GREEN('PR:')} ${ghprbPullAuthorLoginMention} ${ghprbPullLink} $ghprbPullTitle"
}
}
stage ("Prepare (triggered by hand)") {
when { not { expression { IS_TRIGGERED_BY_PR } } }
steps {
echo GREEN("Triggered by hand, so building for master branch")
deleteDir() /* clean up workspace */
git 'git@github.com:checkstyle/checkstyle.git' /* clone the master branch */
}
}
stage('Build') {
parallel {
stage('Package') {
steps {
sh "mvn -e -B package"
}
}
}
}
}
post {
always {
// Clean up workspace
deleteDir()
}
}
}