forked from cloudogu/ecosystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
211 lines (183 loc) · 6.42 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!groovy
// todo
// - setup output
// required plugins
// - http://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin
node('vagrant') {
properties([
// Keep only the last x builds to preserve space
buildDiscarder(logRotator(numToKeepStr: '10')),
// Don't run concurrent builds for a branch, because they use the same workspace directory
disableConcurrentBuilds()
])
stage('Checkout') {
checkout scm
}
try {
stage('Provision') {
timeout(15) {
writeVagrantConfiguration()
sh 'rm -f setup.staging.json setup.json'
sh 'vagrant up'
}
}
stage('Setup') {
timeout(5) {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'cesmarvin-setup', usernameVariable: 'TOKEN_ID', passwordVariable: 'TOKEN_SECRET']]) {
sh "vagrant ssh -c \"sudo cesapp login ${env.TOKEN_ID} ${env.TOKEN_SECRET}\""
}
writeSetupStagingJSON()
sh 'vagrant ssh -c "sudo mv /vagrant/setup.staging.json /etc/ces/setup.staging.json"'
sh 'vagrant ssh -c "sudo mv /etc/ces/setup.staging.json /etc/ces/setup.json"'
sh 'vagrant ssh -c "while sudo pgrep -u root ces-setup > /dev/null; do sleep 1; done"'
sh 'vagrant ssh -c "sudo journalctl -u ces-setup -n 100"'
}
}
stage('Start Dogus') {
timeout(15) {
// TODO wait for all
sh 'vagrant ssh -c "sudo cesapp healthy --wait --timeout 600 --fail-fast cas"'
sh 'vagrant ssh -c "sudo cesapp healthy --wait --timeout 600 --fail-fast jenkins"'
sh 'vagrant ssh -c "sudo cesapp healthy --wait --timeout 600 --fail-fast scm"'
}
}
stage('Integration Tests') {
timeout(10) {
def seleniumChromeImage = docker.image('selenium/standalone-chrome:3.3.0')
def seleniumChromeContainer = seleniumChromeImage.run('-p 4444')
// checkout integration-tests into
checkout([$class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'integration-tests']], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/cloudogu/integration-tests']]])
try {
def seleniumChromeIP = containerIP(seleniumChromeContainer)
def cesIP = getCesIP()
docker.image('cloudogu/gauge-java:latest').inside("-v ${HOME}/.m2:/maven -e BROWSER=REMOTE -e SELENIUM_URL=http://${seleniumChromeIP}:4444/wd/hub -e gauge_jvm_args=-Deco.system=https://${cesIP}") {
sh '/startup.sh /bin/bash -c "cd integration-tests && mvn test"'
}
} finally {
seleniumChromeContainer.stop()
// archive test results
junit 'integration-tests/reports/xml-report/*.xml'
// publish gauge results
publishHTML([
allowMissing : false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : 'integration-tests/reports/html-report',
reportFiles : 'index.html',
reportName : 'Integration Test Report'
])
}
}
}
} finally {
stage('Clean') {
sh 'vagrant destroy -f'
}
}
}
String getCesIP() {
// log into vagrant vm and get the ip from the eth1, which should the configured private network
sh "vagrant ssh -c \"ip addr show dev eth1\" | grep 'inet ' | awk '{print \$2}' | awk -F'/' '{print \$1}' > vagrant.ip"
return readFile('vagrant.ip').trim()
}
String containerIP(container) {
sh "docker inspect -f {{.NetworkSettings.IPAddress}} ${container.id} > container.ip"
return readFile('container.ip').trim()
}
void writeVagrantConfiguration() {
//adjust the vagrant config for local-execution as needed for the integration tests
writeFile file: '.vagrant.rb', text: """
# override public network with a private one
config.vm.networks.each do |n|
if n[0] == :public_network
n[0] = :private_network
n[1][:type] = "dhcp"
end
end
# increase boot timeout
config.vm.boot_timeout = 600
config.vm.provider "virtualbox" do |v|
v.memory = 8192
v.cpus = 2
# v.linked_clone = true
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
end
"""
}
void writeSetupStagingJSON() {
//configure setup
// - to install all Dogus
// - to work in embedded mode
// - have an admin as 'admin/adminpw'
writeFile file: 'setup.staging.json', text: """
{
"token":{
"ID":"",
"Secret":"",
"Completed":true
},
"region":{
"locale":"en_US.utf8",
"timeZone":"Europe/Berlin",
"completed":true
},
"naming":{
"fqdn":"${getCesIP()}",
"hostname":"ces",
"domain":"ces.local",
"certificateType":"selfsigned",
"certificate":"",
"certificateKey":"",
"relayHost":"mail.ces.local",
"completed":true
},
"dogus":{
"defaultDogu":"cockpit",
"install":[
"official/cas",
"official/cockpit",
"official/jenkins",
"official/nginx",
"official/ldap",
"official/postfix",
"official/postgresql",
"official/redmine",
"official/registrator",
"official/scm",
"official/smeagol",
"official/sonar",
"official/nexus",
"official/usermgt"
],
"completed":true
},
"admin":{
"username":"admin",
"mail":"[email protected]",
"password":"adminpw",
"adminGroup":"CesAdministrators",
"adminMember":true,
"confirmPassword":"adminpw",
"completed":true
},
"userBackend":{
"port":"389",
"useUserConnectionToFetchAttributes":true,
"dsType":"embedded",
"attributeID":"uid",
"attributeFullname":"cn",
"attributeMail":"mail",
"attributeGroup":"memberOf",
"searchFilter":"(objectClass=person)",
"host":"ldap",
"completed":true
},
"unixUser":{
"Name":"",
"Password":""
},
"registryConfig": {
}
}"""
}