forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacsengine-svc.groovy
146 lines (141 loc) · 5.95 KB
/
acsengine-svc.groovy
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
#!/usr/bin/env groovy
node("slave") {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'AZURE_CLI_SPN_ACS_TEST',
passwordVariable: 'SPN_PASSWORD', usernameVariable: 'SPN_USER']]) {
timestamps {
wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) {
env.GOPATH="${WORKSPACE}"
env.PATH="${env.PATH}:${env.GOPATH}/bin"
def clone_dir = "${env.GOPATH}/src/github.com/Azure/acs-engine"
env.HOME=clone_dir
String locations_str = "${LOCATIONS}"
String sendTo = "${SEND_TO}".trim()
Integer timeoutInMinutes = STAGE_TIMEOUT.toInteger()
def autoclean="${AUTOCLEAN}"
if(locations_str.equals("all")) {
locations_str = "\
australiaeast \
brazilsouth \
canadacentral canadaeast \
centralindia southindia \
centralus eastus2 eastus northcentralus southcentralus westcentralus westus2 westus \
eastasia southeastasia \
koreacentral koreasouth \
japaneast japanwest \
northeurope westeurope \
uksouth ukwest"
}
def locations = locations_str.tokenize('[ \t\n]+')
dir(clone_dir) {
def img = null
stage('Init') {
deleteDir()
checkout scm
img = docker.build('acs-engine-test', '--pull .')
}
img.inside("-u root:root") {
def junit_dir = "_junit"
try {
String canonicalName = sh(returnStdout: true, script: 'echo "${CLUSTER_DEFINITION%.*}" | sed "s/\\//_/g"').trim()
stage('Setup') {
// Set up Azure
sh("az login --service-principal -u ${SPN_USER} -p ${SPN_PASSWORD} --tenant ${TENANT_ID}")
sh("az account set --subscription ${SUBSCRIPTION_ID}")
// Create report directory
sh("mkdir ${junit_dir}")
// Build and test acs-engine
sh('make ci')
// Create template
env.CLUSTER_DEFINITION = "examples/${CLUSTER_DEFINITION}"
env.ORCHESTRATOR = sh(returnStdout: true, script: './test/step.sh get_orchestrator_type').trim()
sh("printf 'acs-test%x' \$(date '+%s') > INSTANCE_NAME")
env.INSTANCE_NAME = readFile('INSTANCE_NAME').trim()
env.CLUSTER_SERVICE_PRINCIPAL_CLIENT_ID="${CLUSTER_SERVICE_PRINCIPAL_CLIENT_ID}"
env.CLUSTER_SERVICE_PRINCIPAL_CLIENT_SECRET="${CLUSTER_SERVICE_PRINCIPAL_CLIENT_SECRET}"
timeout(time: timeoutInMinutes, unit: 'MINUTES') {
sh('./test/step.sh generate_template')
}
}
for (i = 0; i <locations.size(); i++) {
env.LOCATION = locations[i]
env.RESOURCE_GROUP = "test-acs-svc-${canonicalName}-${env.LOCATION}-${env.BUILD_NUM}"
env.DEPLOYMENT_NAME = "${env.RESOURCE_GROUP}"
env.LOGFILE = pwd()+"/${junit_dir}/${canonicalName}.${env.LOCATION}.log"
env.CLEANUP = "y"
def ok = true
// Deploy
try {
stage("${env.LOCATION} deploy") {
def test = "deploy-${env.LOCATION}"
sh("mkdir -p ${junit_dir}/${test}")
sh("cp ./test/shunit/deploy_template.sh ${junit_dir}/${test}/t.sh")
timeout(time: timeoutInMinutes, unit: 'MINUTES') {
sh("cd ${junit_dir}; shunit.sh -t ${test} > ${test}/junit.xml")
}
sh("grep 'failures=\"0\"' ${junit_dir}/${test}/junit.xml")
}
}
catch(exc) {
env.CLEANUP = autoclean
echo "Exception in [deploy ${canonicalName}/${env.LOCATION}] : ${exc}"
ok = false
}
// Verify deployment
try {
stage("${env.LOCATION} validate") {
if(ok) {
def test = "validate-${env.LOCATION}"
sh("mkdir -p ${junit_dir}/${test}")
sh("cp ./test/shunit/validate_deployment.sh ${junit_dir}/${test}/t.sh")
timeout(time: timeoutInMinutes, unit: 'MINUTES') {
sh("cd ${junit_dir}; shunit.sh -t ${test} > ${test}/junit.xml")
}
sh("grep 'failures=\"0\"' ${junit_dir}/${test}/junit.xml")
}
else {
echo "Skipped verification for ${env.RESOURCE_GROUP}"
}
}
}
catch(exc) {
env.CLEANUP = autoclean
echo "Exception in [validate ${canonicalName}/${env.LOCATION}] : ${exc}"
}
// Clean up
try {
sh('./test/step.sh cleanup')
}
catch(exc) {
echo "Exception ${exc}"
}
} // for (i = 0; i <locations...
// Generate reports
try {
junit("${junit_dir}/**/junit.xml")
archiveArtifacts(allowEmptyArchive: true, artifacts: "${junit_dir}/**/*.log")
if(currentBuild.result == "UNSTABLE") {
currentBuild.result = "FAILURE"
if(sendTo != "") {
emailext(
to: "${sendTo}",
subject: "[ACS Engine Jenkins Failure] ${env.JOB_NAME} #${env.BUILD_NUM}",
body: "${env.BUILD_URL}testReport")
}
}
}
catch(exc) {
echo "Exception ${exc}"
}
}
catch(exc) {
currentBuild.result = "FAILURE"
echo "Exception ${exc}"
}
// Allow for future removal from the host
sh("chmod -R a+rwx ${WORKSPACE}")
}
}
}
}
}
}