-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJenkinsfile
More file actions
139 lines (114 loc) · 3.86 KB
/
Jenkinsfile
File metadata and controls
139 lines (114 loc) · 3.86 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
def workpath_linux_root = "/src/github.com/deis"
def gopath_linux = {
def gopath = pwd() + "/gopath"
env.GOPATH = gopath
gopath
}
def workdir_linux = { String gopath, dest ->
gopath + workpath_linux_root + "/" + dest
}
node('windows') {
def gopath = pwd() + "\\gopath"
env.GOPATH = gopath
def workdir = gopath + "\\src\\github.com\\deis\\controller-sdk-go"
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, "controller-sdk-go")
dir(workdir) {
stage 'Checkout Linux'
checkout scm
stage 'Install Linux'
sh 'make bootstrap'
stage 'Test Linux'
sh 'make test'
}
}
def git_commit = ''
def git_branch = ''
def go_repo = ''
stage 'Go & Git Info'
node('linux') {
def gopath = gopath_linux()
def workdir = workdir_linux(gopath, "controller-sdk-go")
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'
sh 'go list . > tmp/GO_LIST'
git_branch = readFile('tmp/GIT_BRANCH').trim()
git_commit = readFile('tmp/GIT_COMMIT').trim()
go_repo = readFile('tmp/GO_LIST').trim()
if (git_branch != "remotes/origin/master") {
// HACK: get actual PR commit (https://github.com/deis/controller-sdk-go/issues/45)
sh 'git rev-parse HEAD | git log --pretty=%P -n 1 | cut -c1-40 > tmp/ACTUAL_COMMIT'
git_commit = readFile('tmp/ACTUAL_COMMIT').trim()
// convert 'github.com/deis/controller-sdk-go' to 'github.com/${env.CHANGE_AUTHOR}/controller-sdk-go'
go_repo = go_repo.replace('deis', env.CHANGE_AUTHOR)
}
}
}
stage 'Checkout workflow-cli repo and build/deploy with appropriate updates'
node('linux') {
def repo = "workflow-cli"
def gopath = gopath_linux()
def workdir = workdir_linux(gopath, repo)
// vars/closures around uploading artifacts to gcs
def keyfile = "tmp/key.json"
def getBasePath = { String filepath ->
def filename = filepath.lastIndexOf(File.separator)
return filepath.substring(0, filename)
}
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}"
sh "make upload-gcs"
}
}
dir(workdir) {
stage "Checkout ${repo}"
git url: "https://github.com/deis/${repo}.git", branch: "master"
stage "Build ${repo}"
if (git_branch != "remotes/origin/master") {
echo "Skipping build of 386 binaries to shorten CI for Pull Requests"
env.BUILD_ARCH = "amd64"
}
sh 'make bootstrap'
stage "Update local glide.yaml with controller-sdk-go repo '${go_repo}' and version '${git_commit}'"
def pattern = "github\\.com\\/deis\\/controller-sdk-go\\n\\s+version:\\s+[a-f0-9]+"
def replacement = "${go_repo.replace("/", "\\/")}\\n version: ${git_commit}"
sh "perl -i -0pe 's/${pattern}/${replacement}/' glide.yaml"
def glideYaml = readFile('glide.yaml')
echo "Updated glide.yaml:\n${glideYaml}"
sh 'make glideup'
sh "VERSION=${git_commit.take(7)} make build-revision"
stage "Deploy ${repo}"
upload_artifacts(keyfile)
}
}
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 {
def downstreamJob = git_branch == "remotes/origin/master" ? '/workflow-test' : '/workflow-test-pr'
build job: downstreamJob, parameters: [[$class: 'StringParameterValue', name: 'WORKFLOW_CLI_SHA', value: git_commit]]
true
} catch(error) {
input "Retry the e2e tests?"
false
}
}