-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathJenkinsfile
More file actions
176 lines (149 loc) · 4.07 KB
/
Jenkinsfile
File metadata and controls
176 lines (149 loc) · 4.07 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
def workpath_linux = "/src/github.com/deis/workflow-cli"
def keyfile = "tmp/key.json"
def getBasePath = { String filepath ->
def filename = filepath.lastIndexOf(File.separator)
return filepath.substring(0, filename)
}
def make = { String target ->
try {
sh "make ${target} fileperms"
} catch(error) {
sh "make fileperms"
false
}
}
def upload_artifacts = { String filepath ->
withCredentials([[$class: 'FileBinding', credentialsId: 'e80fd033-dd76-4d96-be79-6c272726fb82', variable: 'GCSKEY']]) {
sh "mkdir -p ${getBasePath(filepath)}"
sh "cat \"\${GCSKEY}\" > ${filepath}"
make 'upload-gcs'
}
}
def gopath_linux = {
def gopath = pwd() + "/gopath"
env.GOPATH = gopath
gopath
}
def workdir_linux = { String gopath ->
gopath + workpath_linux
}
def sh = { String cmd ->
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
sh cmd
}
}
node('windows') {
def gopath = pwd() + "\\gopath"
env.GOPATH = gopath
def workdir = gopath + "\\src\\github.com\\deis\\workflow-cli"
def pscmd = { String cmd ->
"powershell -NoProfile -ExecutionPolicy Bypass -Command \"${cmd}\""
}
dir(workdir) {
stage 'Checkout Windows'
checkout scm
stage 'Install Windows'
bat pscmd('.\\make bootstrap')
stage 'Test Windows'
bat pscmd('.\\make test')
}
}
node('linux') {
def gopath = gopath_linux()
def workdir = workdir_linux(gopath)
dir(workdir) {
stage 'Checkout Linux'
checkout scm
stage 'Install Linux'
make 'bootstrap'
stage 'Test Linux'
make 'test'
}
}
def git_commit = ''
def git_branch = ''
stage 'Git Info'
node('linux') {
def gopath = gopath_linux()
def workdir = workdir_linux(gopath)
dir(workdir) {
checkout scm
// HACK: Recommended approach for getting command output is writing to and then reading a file.
sh 'mkdir -p tmp'
sh 'git describe --all > tmp/GIT_BRANCH'
sh 'git rev-parse HEAD > tmp/GIT_COMMIT'
git_branch = readFile('tmp/GIT_BRANCH').trim()
git_commit = readFile('tmp/GIT_COMMIT').trim()
}
}
stage 'Build and Upload Artifacts'
parallel(
revision: {
node('linux') {
def gopath = gopath_linux()
def workdir = workdir_linux(gopath)
dir(workdir) {
checkout scm
if (git_branch != "remotes/origin/master") {
echo "Skipping build of 386 binaries to shorten CI for Pull Requests"
env.BUILD_ARCH = "amd64"
}
make 'bootstrap'
env.VERSION = git_commit.take(7)
make 'build-revision'
upload_artifacts(keyfile)
}
}
},
latest: {
node('linux') {
def gopath = gopath_linux()
def workdir = workdir_linux(gopath)
dir(workdir) {
checkout scm
if (git_branch == "remotes/origin/master") {
make 'bootstrap'
make 'build-latest'
upload_artifacts(keyfile)
} else {
echo "Skipping build of latest artifacts because this build is not on the master branch (branch: ${git_branch})"
}
}
}
}
)
stage 'Trigger e2e tests'
// If build is on master, trigger workflow-test, otherwise, assume build is a PR and trigger workflow-test-pr
waitUntil {
try {
if (git_branch == "remotes/origin/master") {
build job: '/workflow-test', parameters: [[$class: 'StringParameterValue', name: 'WORKFLOW_CLI_SHA', value: git_commit]]
} else {
build job: '/workflow-test-pr', parameters: [[$class: 'StringParameterValue', name: 'WORKFLOW_CLI_SHA', value: git_commit]]
}
true
} catch(error) {
node('linux') {
if (git_branch != "remotes/origin/master") {
withCredentials([[$class: 'StringBinding', credentialsId: '8a727911-596f-4057-97c2-b9e23de5268d', variable: 'SLACKEMAIL']]) {
mail body: """<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<div>Author: ${env.CHANGE_AUTHOR}<br/>
Branch: ${env.BRANCH_NAME}<br/>
Commit: ${env.CHANGE_TITLE}<br/>
<a href="${env.BUILD_URL}console">Click here</a> to view logs.</p>
<a href="${env.BUILD_URL}input/">Click here</a> to restart e2e.</p>
</div>
</html>
""", from: 'jenkins@ci.deis.io', subject: 'Workflow CLI E2E Test Failure', to: env.SLACKEMAIL, mimeType: 'text/html'
}
input "Retry the e2e tests?"
}
}
false
}
}