forked from gravitational/gravity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.nightly
163 lines (158 loc) · 5.76 KB
/
Jenkinsfile.nightly
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
#!/usr/bin/env groovy
def propagateParamsToEnv() {
for (param in params) {
if (env."${param.key}" == null) {
env."${param.key}" = param.value
}
}
}
def withBuildResult(Closure body) {
def previousBuildResult = currentBuild.previousBuild?.result
try {
body()
currentBuild.result = 'SUCCESS'
} catch(InterruptedException e) {
currentBuild.result = 'ABORTED'
throw e
} catch(e) {
currentBuild.result = 'FAILURE'
throw e
} finally {
sendBuildNotification(currentBuild.result, previousBuildResult)
}
}
/*
* sendBuildNotification sends a notification to slack if the build
* has recovered from a failure (i.e. had failed previously)
* or failed.
* See https://github.com/jenkinsci/jenkins/blob/jenkins-2.121.1/core/src/main/java/hudson/model/Result.java
* for the list of possible values for currentBuild.result.
*/
def sendBuildNotification(String currentBuildResult, String previousBuildResult) {
currentBuildResult = currentBuildResult ?: "SUCCESS"
previousBuildResult = previousBuildResult ?: "SUCCESS"
def color = "warning"
def message = "${env.JOB_NAME} ${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)"
if (currentBuildResult == "SUCCESS") {
color = "good"
}
def shouldNotify = currentBuildResult != "STARTED" &&
currentBuildResult != "SUCCESS" &&
currentBuildResult != "ABORTED" ||
(currentBuildResult == "SUCCESS" && previousBuildResult != "SUCCESS")
if (shouldNotify) {
slackSend(color: color, message: message)
}
}
properties([
disableConcurrentBuilds(),
// Schedule a daily build between 6:00am and 6:30am UTC (10:00pm-10:30pm PST)
pipelineTriggers([cron('H(0-30) 06 * * 1-5')]),
parameters([
choice(choices: ["run", "skip"].join("\n"),
defaultValue: 'run',
description: 'Run or skip robotest system wide tests.',
name: 'RUN_ROBOTEST'),
choice(choices: ["true", "false"].join("\n"),
defaultValue: 'true',
description: 'Destroy all VMs on success.',
name: 'DESTROY_ON_SUCCESS'),
choice(choices: ["true", "false"].join("\n"),
defaultValue: 'true',
description: 'Destroy all VMs on failure.',
name: 'DESTROY_ON_FAILURE'),
choice(choices: ["true", "false"].join("\n"),
defaultValue: 'true',
description: 'Abort all tests upon first failure.',
name: 'FAIL_FAST'),
choice(choices: ["gce"].join("\n"),
defaultValue: 'gce',
description: 'Cloud provider to deploy to.',
name: 'DEPLOY_TO'),
string(name: 'PARALLEL_TESTS',
defaultValue: '4',
description: 'Number of parallel tests to run.'),
string(name: 'REPEAT_TESTS',
defaultValue: '1',
description: 'How many times to repeat each test.'),
string(name: 'ROBOTEST_VERSION',
defaultValue: 'stable-gce',
description: 'Robotest tag to use.'),
choice(choices: ["true", "false"].join("\n"),
defaultValue: 'true',
description: 'Whether to use preemptible VMs.',
name: 'GCE_PREEMPTIBLE'),
choice(choices: ["custom-4-8192", "custom-8-8192"].join("\n"),
defaultValue: 'custom-4-8192',
description: 'VM type to use.',
name: 'GCE_VM'),
]),
])
timestamps {
withBuildResult {
node {
stage('checkout') {
checkout scm
sh "git submodule update --init --recursive"
sh "sudo git clean -ffdx" // supply -f flag twice to force-remove untracked dirs with .git subdirs (e.g. submodules)
}
stage('params') {
echo "${params}"
propagateParamsToEnv()
}
stage('clean') {
sh "make -C e clean"
}
stage('build-gravity') {
withCredentials([
[$class: 'SSHUserPrivateKeyBinding', credentialsId: '08267d86-0b3a-4101-841e-0036bf780b11', keyFileVariable: 'GITHUB_SSH_KEY'],
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'jenkins-aws-s3',
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
],
]) {
sh 'make -C e production telekube opscenter'
}
}
}
throttle(['robotest']) {
node {
stage('build-and-test') {
parallel (
build : {
withCredentials([
[$class: 'SSHUserPrivateKeyBinding', credentialsId: '08267d86-0b3a-4101-841e-0036bf780b11', keyFileVariable: 'GITHUB_SSH_KEY']]) {
sh 'make test && make -C e test'
}
},
robotest : {
if (params.RUN_ROBOTEST == 'run') {
withCredentials([
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: 'jenkins-aws-s3',
usernameVariable: 'AWS_ACCESS_KEY_ID',
passwordVariable: 'AWS_SECRET_ACCESS_KEY',
],
[$class: 'StringBinding', credentialsId: 'GET_GRAVITATIONAL_IO_APIKEY', variable: 'GET_GRAVITATIONAL_IO_APIKEY'],
[$class: 'FileBinding', credentialsId:'ROBOTEST_LOG_GOOGLE_APPLICATION_CREDENTIALS', variable: 'GOOGLE_APPLICATION_CREDENTIALS'],
[$class: 'FileBinding', credentialsId:'OPS_SSH_KEY', variable: 'SSH_KEY'],
[$class: 'FileBinding', credentialsId:'OPS_SSH_PUB', variable: 'SSH_PUB'],
]) {
sh """
make -C e robotest-run-nightly \
AWS_KEYPAIR=ops \
AWS_REGION=us-east-1 \
ROBOTEST_VERSION=$ROBOTEST_VERSION"""
}
} else {
echo 'skipped system tests'
}
} )
}
}
}
}
}