blob: b6c8b27270940b3357997c780bc25e9430204f5f [file] [log] [blame]
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +04001/**
2 * Tests model manager UI
3 * DEFAULT_GIT_REF
4 * DEFAULT_GIT_URL
5 * NPM_DOCKER_IMG
6 */
7
8def common = new com.mirantis.mk.Common()
9def gerrit = new com.mirantis.mk.Gerrit()
10def dockerLib = new com.mirantis.mk.Docker()
11
12def gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit'
13def slaveNode = env.SLAVE_NODE ?: 'python&&docker'
14def gerritRef = env.GERRIT_REFSPEC ?: null
15def defaultGitRef = env.DEFAULT_GIT_REF ?: null
16def defaultGitUrl = env.DEFAULT_GIT_URL ?: null
17
18def checkouted = false
19def testReportFile = 'test-report.html'
20
21timeout(time: 30, unit: 'MINUTES') {
22 node(slaveNode) {
23 def img = dockerLib.getImage(env.NPM_DOCKER_IMG, "npm:8.12.0")
24 try {
25 if (fileExists("build/")) {
26 common.infoMsg('Cleaning test env')
27 sh("rm -rf build/")
28 }
29 stage("checkout") {
30 if (gerritRef) {
31 // job is triggered by Gerrit
32 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials, true)
33 if (gerritChange.commitMessage.contains("WIP")) {
34 common.successMsg("Commit message contains WIP, skipping tests") // do nothing
35 } else {
36 // test if change aren't already merged
37 def merged = gerritChange.status == "MERGED"
38 if (!merged) {
39 checkouted = gerrit.gerritPatchsetCheckout([
40 credentialsId: gerritCredentials
41 ])
42 } else {
43 common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them")
44 }
45 }
46 } else if (defaultGitRef && defaultGitUrl) {
47 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
48 } else {
49 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF are null")
50 }
51 }
52
53 if (checkouted) {
54 stage("test") {
Ivan Berezovskiy915b22a2018-12-29 16:14:21 +040055 img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/ -e npm_config_cache=/operations-ui/.npm -e CI=true") {
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +040056 sh('''#!/bin/bash -xe
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +040057 cd /operations-ui
58 npm install
59 npm test
60 ''')
61 }
62 }
63 }
64 } catch (Throwable e) {
65 // If there was an error or exception thrown, the build failed
66 currentBuild.result = "FAILURE"
67 throw e
68 } finally {
69 if (fileExists(testReportFile)) {
70 archiveArtifacts artifacts: testReportFile
71 }
Ivan Berezovskiy915b22a2018-12-29 16:14:21 +040072 stage("Cleanup"){
73 img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/") {
74 sh("rm -rf /operations-ui/*")
75 }
76 }
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +040077 }
78 }
79}