This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
/
TestKitchen.groovy
87 lines (72 loc) · 2.11 KB
/
TestKitchen.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
#!/usr/bin/env groovy
package org.typo3.chefci.v1
def createKitchenYaml(){
echo "createKitchenYaml()"
if (fileExists('.kitchen.docker.yml')) {
echo('Using the cookbooks .kitchen.docker.yml')
} else {
echo('Placing default .kitchen.docker.yml file in workspace')
writeFile(
file: '.kitchen.docker.yml',
text: '''
driver:
name: docker
use_sudo: false
provision_command:
- apt-get install -y wget # this is only needed as long as Debian 8 does not trust bintray.com
- apt-get install -y net-tools cron
''')
}
}
def setKitchenLocalEnv(){
env.KITCHEN_LOCAL_YAML=".kitchen.docker.yml"
}
def ArrayList<String> getInstances(){
def tkInstanceNames = []
node {
// read out the list of test instances from `kitchen list`
def lines = sh(script: 'kitchen list', returnStdout: true).split('\n')
// skip the headline, read out all instances
for (int i = 1; i < lines.size(); i++) {
tkInstanceNames << lines[i].tokenize(' ')[0]
}
}
return tkInstanceNames
}
def parallelConverge() {
this.parallelConverge(this.getInstances())
}
def parallelConverge(ArrayList<String> instanceNames) {
def parallelNodes = [:]
for (int i = 0; i < instanceNames.size(); i++) {
def instanceName = instanceNames.get(i)
parallelNodes["tk-${instanceName}"] = this.getNodeForInstance(instanceName)
}
parallel parallelNodes
}
def Closure getNodeForInstance(String instanceName) {
return {
// this node (one per instance) is later executed in parallel
node {
// restore workspace
unstash('cookbook-tk')
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: "XTerm"]) {
sh('kitchen test --destroy always ' + instanceName)
}
}
}
}
def prepare(){
stage "test-kitchen"
node {
this.createKitchenYaml()
this.setKitchenLocalEnv()
stash("cookbook-tk")
}
}
def execute(){
this.prepare()
// this will allocate multiple nodes
this.parallelConverge()
}
return this;