blob: f813524f0474a8f6838f018114e7e38712d88939 [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") {
55 img.inside("-v ${env.WORKSPACE}/:/operations-ui/") {
56 sh('''#!/bin/bash -xe
57 export CI=true
58 cd /operations-ui
59 npm install
60 npm test
61 ''')
62 }
63 }
64 }
65 } catch (Throwable e) {
66 // If there was an error or exception thrown, the build failed
67 currentBuild.result = "FAILURE"
68 throw e
69 } finally {
70 if (fileExists(testReportFile)) {
71 archiveArtifacts artifacts: testReportFile
72 }
73 }
74 }
75}