-
Notifications
You must be signed in to change notification settings - Fork 46
/
test-operations-ui.groovy
81 lines (76 loc) · 3.23 KB
/
test-operations-ui.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
/**
* Tests model manager UI
* DEFAULT_GIT_REF
* DEFAULT_GIT_URL
* NPM_DOCKER_IMG
*/
def common = new com.mirantis.mk.Common()
def gerrit = new com.mirantis.mk.Gerrit()
def dockerLib = new com.mirantis.mk.Docker()
def gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit'
def slaveNode = env.SLAVE_NODE ?: 'python&&docker'
def gerritRef = env.GERRIT_REFSPEC ?: null
def defaultGitRef = env.DEFAULT_GIT_REF ?: null
def defaultGitUrl = env.DEFAULT_GIT_URL ?: null
def checkouted = false
def testReportFile = 'test-report.html'
timeout(time: 30, unit: 'MINUTES') {
node(slaveNode) {
def img = dockerLib.getImage(env.NPM_DOCKER_IMG, "npm:8.12.0")
try {
if (fileExists('build') || fileExists('.npm')) {
common.infoMsg('Cleaning test env')
img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/") {
sh("rm -rf /operations-ui/build/ /operations-ui/.npm")
}
}
stage("checkout") {
if (gerritRef) {
// job is triggered by Gerrit
def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials, true)
if (gerritChange.commitMessage.contains("WIP")) {
common.successMsg("Commit message contains WIP, skipping tests") // do nothing
} else {
// test if change aren't already merged
def merged = gerritChange.status == "MERGED"
if (!merged) {
checkouted = gerrit.gerritPatchsetCheckout([
credentialsId: gerritCredentials
])
} else {
common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them")
}
}
} else if (defaultGitRef && defaultGitUrl) {
checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
} else {
throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF are null")
}
}
if (checkouted) {
stage("test") {
img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/ -e npm_config_cache=/operations-ui/.npm -e CI=true") {
sh('''#!/bin/bash -xe
cd /operations-ui
npm install
npm test
''')
}
}
}
} catch (Throwable e) {
// If there was an error or exception thrown, the build failed
currentBuild.result = "FAILURE"
throw e
} finally {
if (fileExists(testReportFile)) {
archiveArtifacts artifacts: testReportFile
}
stage("Cleanup"){
img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/") {
sh("rm -rf /operations-ui/*")
}
}
}
}
}