-
Notifications
You must be signed in to change notification settings - Fork 33
/
Jenkinsfile
120 lines (111 loc) · 3.49 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
pipeline {
agent {
label 'slave'
}
options {
ansiColor('xterm')
timeout(time: 1, unit: 'HOURS')
timestamps()
}
stages {
stage('check-gh-trust') {
steps {
checkGitHubAccess()
}
}
stage('set-version') {
steps {
script {
sha = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
version = "${new Date().format("yyyy-MM-dd-'T'HH-mm-ss")}-git${sha}"
repo_name_tokens = env.JOB_NAME.split('/')
repo_name = repo_name_tokens.length < 2 ? env.JOB_NAME : repo_name_tokens[repo_name_tokens.length - 2]
}
}
}
stage('parallel-test-cook') {
environment {
DOCKER_REPO = 'docker-push.ocf.berkeley.edu/'
DOCKER_REVISION = "${version}"
}
parallel {
stage('test') {
steps {
script {
sh 'make -q test || if [ "$?" -ne "2" ]; then make test; fi'
}
}
}
stage('cook-image') {
steps {
sh 'make -q cook-image || if [ "$?" -ne "2" ]; then make cook-image; fi'
}
}
}
}
stage('push-to-registry') {
environment {
DOCKER_REPO = 'docker-push.ocf.berkeley.edu/'
DOCKER_REVISION = "${version}"
}
when {
branch 'master'
}
agent {
label 'deploy'
}
steps {
sh 'make -q push-image || if [ "$?" -ne "2" ]; then make push-image; fi'
}
}
stage('deploy-to-prod') {
when {
branch 'master'
}
agent {
label 'deploy'
}
steps {
script {
if (fileExists('kubernetes')) {
kubernetesDeployApp(repo_name, version)
}
}
}
}
stage('deploy-to-preview') {
when {
changeRequest()
}
environment {
DOCKER_REPO = 'docker-push.ocf.berkeley.edu/'
DOCKER_REVISION = "${version}"
}
agent {
label 'deploy'
}
steps {
script {
withKubeConfig([credentialsId: 'kubernetes-deploy-token',
serverUrl: 'https://kubernetes.ocf.berkeley.edu:6443'
]) {
def status = sh returnStatus: true, script: "make preview-deploy PREVIEW_DEPLOY_ID=${env.BRANCH_NAME}"
if (status != 0) {
pullRequest.comment("Preview deployment failed! See Jenkins output for more details: ${env.BUILD_URL}")
} else {
pullRequest.comment("View the preview deployment of this pull request here: https://${env.BRANCH_NAME}.new.ocf.berkeley.edu")
}
}
}
}
}
}
post {
failure {
emailNotification()
}
always {
ircNotification()
}
}
}