blob: f1a8ea2ccaf61c105f3e004f95918757d582a79b [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 {
Ivan Berezovskiyb864ad62019-01-16 20:01:26 +040025 if (fileExists('build') || fileExists('.npm')) {
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +040026 common.infoMsg('Cleaning test env')
Ivan Berezovskiyb864ad62019-01-16 20:01:26 +040027 img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/") {
28 sh("rm -rf /operations-ui/build/ /operations-ui/.npm")
29 }
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +040030 }
31 stage("checkout") {
32 if (gerritRef) {
33 // job is triggered by Gerrit
34 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, gerritCredentials, true)
35 if (gerritChange.commitMessage.contains("WIP")) {
36 common.successMsg("Commit message contains WIP, skipping tests") // do nothing
37 } else {
38 // test if change aren't already merged
39 def merged = gerritChange.status == "MERGED"
40 if (!merged) {
41 checkouted = gerrit.gerritPatchsetCheckout([
42 credentialsId: gerritCredentials
43 ])
44 } else {
45 common.successMsg("Change ${GERRIT_CHANGE_NUMBER} is already merged, no need to test them")
46 }
47 }
48 } else if (defaultGitRef && defaultGitUrl) {
49 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", gerritCredentials)
50 } else {
51 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF are null")
52 }
53 }
54
55 if (checkouted) {
56 stage("test") {
Ivan Berezovskiy915b22a2018-12-29 16:14:21 +040057 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 +040058 sh('''#!/bin/bash -xe
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +040059 cd /operations-ui
60 npm install
61 npm test
62 ''')
63 }
64 }
65 }
66 } catch (Throwable e) {
67 // If there was an error or exception thrown, the build failed
68 currentBuild.result = "FAILURE"
69 throw e
70 } finally {
71 if (fileExists(testReportFile)) {
72 archiveArtifacts artifacts: testReportFile
73 }
Ivan Berezovskiy915b22a2018-12-29 16:14:21 +040074 stage("Cleanup"){
75 img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/") {
76 sh("rm -rf /operations-ui/*")
77 }
78 }
Ivan Berezovskiyf959aa82018-12-28 19:28:51 +040079 }
80 }
81}