forked from eclipse/xtext-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
149 lines (140 loc) · 3.65 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
pipeline {
agent {
kubernetes {
label 'xtext-core-' + (env.BRANCH_NAME.replace('/','_')) + '-' + env.BUILD_NUMBER
defaultContainer 'xtext-buildenv'
yaml '''
apiVersion: v1
kind: Pod
spec:
containers:
- name: jnlp
args: ['\$(JENKINS_SECRET)', '\$(JENKINS_NAME)']
resources:
limits:
memory: "0.4Gi"
cpu: "0.2"
requests:
memory: "0.4Gi"
cpu: "0.2"
volumeMounts:
- mountPath: /home/jenkins/.ssh
name: volume-known-hosts
- name: xtext-buildenv
image: docker.io/smoht/xtext-buildenv:0.7
tty: true
resources:
limits:
memory: "3.6Gi"
cpu: "1.0"
requests:
memory: "3.6Gi"
cpu: "1.0"
volumeMounts:
- name: settings-xml
mountPath: /home/jenkins/.m2/settings.xml
subPath: settings.xml
readOnly: true
- name: m2-repo
mountPath: /home/jenkins/.m2/repository
- name: volume-known-hosts
mountPath: /home/jenkins/.ssh
volumes:
- name: volume-known-hosts
configMap:
name: known-hosts
- name: settings-xml
secret:
secretName: m2-secret-dir
items:
- key: settings.xml
path: settings.xml
- name: m2-repo
emptyDir: {}
'''
}
}
environment {
DOWNSTREAM_JOBS = 'xtext-extras'
}
parameters {
booleanParam(
name: 'TRIGGER_DOWNSTREAM_BUILD',
defaultValue: (env.BRANCH_NAME.startsWith('milestone')||env.BRANCH_NAME.startsWith('release')),
description: 'Should downstream jobs for the same branch be triggered on successful build?'
)
}
options {
buildDiscarder(logRotator(numToKeepStr:'15'))
disableConcurrentBuilds()
timeout(time: 120, unit: 'MINUTES')
}
// Build stages
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Gradle Build') {
steps {
sh './1-gradle-build.sh'
}
}
stage('Maven Build') {
steps {
sh './2-maven-build.sh'
}
}
}
post {
always {
junit testResults: '**/build/test-results/test/*.xml'
}
success {
archiveArtifacts artifacts: 'build/**'
script {
if (params.TRIGGER_DOWNSTREAM_BUILD==true) {
DOWNSTREAM_JOBS.split(',').each {
def downstreamUrl = new URL("${env.JENKINS_URL}/job/$it/job/${env.BRANCH_NAME}")
def boolean downstreamJobExists = sh(script: "curl -L -s -o /dev/null -I -w '%{http_code}' ${downstreamUrl}", returnStdout: true) == "200"
if (downstreamJobExists) {
build job: "$it/${env.BRANCH_NAME}", wait: false, parameters: [booleanParam(name: 'TRIGGER_DOWNSTREAM_BUILD', value: "${params.TRIGGER_DOWNSTREAM_BUILD}")]
}
}
}
}
}
cleanup {
script {
def curResult = currentBuild.currentResult
def lastResult = 'NEW'
if (currentBuild.previousBuild != null) {
lastResult = currentBuild.previousBuild.result
}
if (curResult != 'SUCCESS' || lastResult != 'SUCCESS') {
def color = ''
switch (curResult) {
case 'SUCCESS':
color = '#00FF00'
break
case 'UNSTABLE':
color = '#FFFF00'
break
case 'FAILURE':
color = '#FF0000'
break
default: // e.g. ABORTED
color = '#666666'
}
slackSend (
message: "${lastResult} => ${curResult}: <${env.BUILD_URL}|${env.JOB_NAME}#${env.BUILD_NUMBER}>",
botUser: true,
channel: 'xtext-builds',
color: "${color}"
)
}
}
}
}
}