forked from kubernetes-retired/service-catalog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
161 lines (135 loc) · 5.16 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
150
151
152
153
154
155
156
157
158
159
160
161
#!groovy
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Jenkins continuous integration
//
// Parameters Jenkins needs to / can supply:
//
// TEST_PROJECT: Google Cloud Project ID of the project to use for testing.
// TEST_ZONE: GCP Zone in which to create test GKE cluster
// TEST_ACCOUNT: GCP service account credentials (JSON file) to use for testing.
def repo_url = params.REPO_URL
def updatePullRequest(flow, success = false) {
def state, message
switch (flow) {
case 'run':
state = 'PENDING'
message = "Running presubmits at ${env.BUILD_URL} ..."
break
case 'verify':
state = success ? 'SUCCESS' : 'FAILURE'
message = "${success ? 'Successful' : 'Failed'} presubmits. " +
"Details at ${env.BUILD_URL}."
break
default:
error('flow can only be run or verify')
}
step([
$class: "GitHubCommitStatusSetter",
reposSource: [$class: "ManuallyEnteredRepositorySource", url: "${repo_url}"],
contextSource: [$class: "ManuallyEnteredCommitContextSource", context: "${JOB_NAME}"],
errorHandlers: [[$class: "ChangingBuildStatusErrorHandler", result: "UNSTABLE"]],
statusResultSource: [ $class: "ConditionalStatusResultSource", results: [[$class: "AnyBuildResult", message: message, state: state]] ]
]);
}
// Verify required parameters
if (! params.TEST_PROJECT) {
error 'Missing required parameter TEST_PROJECT'
}
if (! params.TEST_ACCOUNT) {
error 'Missing required parameter TEST_ACCOUNT'
}
def test_project = params.TEST_PROJECT
def test_account = params.TEST_ACCOUNT
def test_zone = params.TEST_ZONE ?: 'us-west1-b'
def namespace = 'catalog'
def root_path = 'src/github.com/kubernetes-incubator/service-catalog'
def timeoutMin = 50
def certFolder = '/tmp/sc-certs'
node {
echo "Service Catalog end-to-end test"
sh "sudo rm -rf ${env.WORKSPACE}/*"
sh "rm -rf ${certFolder} && mkdir ${certFolder}"
updatePullRequest('run')
// Checkout the source code.
checkout scm
env.GOPATH = env.WORKSPACE
env.ROOT = "${env.WORKSPACE}/${root_path}"
env.KUBECONFIG = "${env.ROOT}/k8s-kubeconfig"
dir([path: env.ROOT]) {
// Run build.
def clustername = "jenkins-" + sh([returnStdout: true, script: '''openssl rand \
-base64 100 | tr -dc a-z0-9 | cut -c -25''']).trim()
def version = sh([returnStdout: true, script: 'git describe --always --abbrev=7 --dirty']).trim()
try {
timeout(timeoutMin) {
// These are done in parallel since creating the cluster takes a while,
// and the build doesn't depend on it.
parallel(
'Cluster': {
withCredentials([file(credentialsId: "${test_account}", variable: 'TEST_SERVICE_ACCOUNT')]) {
sh """${env.ROOT}/contrib/jenkins/init_cluster.sh ${clustername} \
--project ${test_project} \
--zone ${test_zone} \
--credentials ${env.TEST_SERVICE_ACCOUNT}"""
}
},
'Build & Unit/Integration Tests': {
sh """${env.ROOT}/contrib/jenkins/build.sh \
--project ${test_project} \
--version ${version}"""
}
)
// Run through the walkthrough on the cluster, once with an etcd-backed API server and once
// with a TPR-backed one.
sh """${env.ROOT}/contrib/jenkins/test_walkthrough.sh \
--registry gcr.io/${test_project}/catalog/ \
--version ${version} \
--cleanup \
--fix-auth \
--create-artifacts
"""
ansiColor('xterm-darker-gray') {
// Run the e2e test framework
sh """${env.ROOT}/contrib/jenkins/run_e2e.sh \
--registry gcr.io/${test_project}/catalog/ \
--version ${version} \
--cleanup \
--create-artifacts
"""
}
echo 'Run succeeded.'
}
} catch (Exception e) {
echo 'Run failed.'
print e
currentBuild.result = 'FAILURE'
} finally {
archiveArtifacts artifacts: 'walkthrough*.txt', fingerprint: true
archiveArtifacts artifacts: 'e2e*.txt', fingerprint: true
try {
sh "rm -rf ${certFolder}"
sh """${env.ROOT}/contrib/jenkins/cleanup_cluster.sh --kubeconfig ${KUBECONFIG}"""
} catch (Exception e) {
echo 'Exception caught during cleanup.'
currentBuild.result = 'FAILURE'
}
}
if (currentBuild.result == 'FAILURE') {
updatePullRequest('verify', false)
error 'Build failed.'
}
}
updatePullRequest('verify', true)
archiveArtifacts artifacts: 'coverage.html', allowEmptyArchive: true, onlyIfSuccessful: true
}