-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathJenkinsfile
109 lines (98 loc) · 3.15 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
// Keep artifacts for last 3 builds, disable concurrent builds, build when /metaborg/spoofax-releng/master job builds.
properties([
buildDiscarder(logRotator(artifactNumToKeepStr: '3'))
, disableConcurrentBuilds()
, pipelineTriggers([upstream(threshold: hudson.model.Result.SUCCESS, upstreamProjects: '/metaborg/spoofax-releng/master')])
])
node('spoofax-buildenv-jenkins') {
def slackChannel = '#spoofax-dev'
// In Jenkins, under Tools, add a JDK Installation with:
// - Name: JDK 11
// - JAVA_HOME: /usr/lib/jvm/java-11-openjdk-amd64
// - Install automatically: false
// Ensure the JDK 11 is available in the Spoofax Docker image at the specified path.
jdk = tool name: 'JDK 11'
env.JAVA_HOME = "${jdk}"
try {
stage('Echo') {
// Print important variables and versions for debugging purposes.
sh 'env'
sh 'bash --version'
sh 'git --version'
sh 'python3 --version'
sh 'pip3 --version'
sh "$JAVA_HOME/bin/java -version"
sh "$JAVA_HOME/bin/javac -version"
sh 'mvn --version'
}
stage('Checkout') {
checkout scm
sh 'git clean -ddffxx'
}
stage('Build and Test') {
withMaven(
mavenLocalRepo: ".repository"
, globalMavenSettingsFilePath: ".mvn/settings.xml"
, mavenOpts: '-Xmx1G -Xms1G -Xss16m'
) {
sh 'mvn -B -U -e clean -DforceContextQualifier=\$(date +%Y%m%d%H%M)'
sh 'mvn -B -U -e install -DforceContextQualifier=\$(date +%Y%m%d%H%M)'
}
}
stage('Archive') {
archiveArtifacts(
artifacts: 'org.metaborg.lang.tiger.eclipse.site/target/site/'
, excludes: null
, onlyIfSuccessful: true
)
}
stage('Cleanup') {
sh "git clean -ddffxx"
}
} catch(org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
if(e.causes.size() == 0) {
throw e // No causes, signals abort.
} else {
notifyFail(slackChannel)
throw e
}
} catch(hudson.AbortException e) {
if(e.getMessage().contains('script returned exit code 143')) {
throw e // Exit code 143 means SIGTERM (process was killed), signals abort.
} else {
notifyFail(slackChannel)
throw e
}
} catch(e) {
notifyFail(slackChannel)
throw e
}
notifySuccess(slackChannel)
}
def createMessage(String message) {
return "${env.JOB_NAME} - ${env.BUILD_NUMBER} - ${message} (<${env.BUILD_URL}|Status> <${env.BUILD_URL}console|Console>)"
}
def notifyFail(String channel) {
if(!channel) {
return
}
def prevBuild = currentBuild.getPreviousBuild()
if(prevBuild) {
if('SUCCESS'.equals(prevBuild.getResult())) {
slackSend channel: channel, color: 'danger', message: createMessage('failed')
} else {
slackSend channel: channel, color: 'danger', message: createMessage('still failing')
}
} else {
slackSend channel: channel, color: 'danger', message: createMessage('failed')
}
}
def notifySuccess(String channel) {
if(!channel) {
return
}
def prevBuild = currentBuild.getPreviousBuild()
if(prevBuild && !'SUCCESS'.equals(prevBuild.getResult())) {
slackSend channel: channel, color: 'good', message: createMessage('fixed')
}
}