Ivan Berezovskiy | f959aa8 | 2018-12-28 19:28:51 +0400 | [diff] [blame] | 1 | /** |
| 2 | * Tests model manager UI |
| 3 | * DEFAULT_GIT_REF |
| 4 | * DEFAULT_GIT_URL |
| 5 | * NPM_DOCKER_IMG |
| 6 | */ |
| 7 | |
| 8 | def common = new com.mirantis.mk.Common() |
| 9 | def gerrit = new com.mirantis.mk.Gerrit() |
| 10 | def dockerLib = new com.mirantis.mk.Docker() |
| 11 | |
| 12 | def gerritCredentials = env.CREDENTIALS_ID ?: 'gerrit' |
| 13 | def slaveNode = env.SLAVE_NODE ?: 'python&&docker' |
| 14 | def gerritRef = env.GERRIT_REFSPEC ?: null |
| 15 | def defaultGitRef = env.DEFAULT_GIT_REF ?: null |
| 16 | def defaultGitUrl = env.DEFAULT_GIT_URL ?: null |
| 17 | |
| 18 | def checkouted = false |
| 19 | def testReportFile = 'test-report.html' |
| 20 | |
| 21 | timeout(time: 30, unit: 'MINUTES') { |
| 22 | node(slaveNode) { |
| 23 | def img = dockerLib.getImage(env.NPM_DOCKER_IMG, "npm:8.12.0") |
| 24 | try { |
Ivan Berezovskiy | b864ad6 | 2019-01-16 20:01:26 +0400 | [diff] [blame] | 25 | if (fileExists('build') || fileExists('.npm')) { |
Ivan Berezovskiy | f959aa8 | 2018-12-28 19:28:51 +0400 | [diff] [blame] | 26 | common.infoMsg('Cleaning test env') |
Ivan Berezovskiy | b864ad6 | 2019-01-16 20:01:26 +0400 | [diff] [blame] | 27 | img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/") { |
| 28 | sh("rm -rf /operations-ui/build/ /operations-ui/.npm") |
| 29 | } |
Ivan Berezovskiy | f959aa8 | 2018-12-28 19:28:51 +0400 | [diff] [blame] | 30 | } |
| 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 Berezovskiy | 915b22a | 2018-12-29 16:14:21 +0400 | [diff] [blame] | 57 | img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/ -e npm_config_cache=/operations-ui/.npm -e CI=true") { |
Ivan Berezovskiy | f959aa8 | 2018-12-28 19:28:51 +0400 | [diff] [blame] | 58 | sh('''#!/bin/bash -xe |
Ivan Berezovskiy | f959aa8 | 2018-12-28 19:28:51 +0400 | [diff] [blame] | 59 | 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 Berezovskiy | 915b22a | 2018-12-29 16:14:21 +0400 | [diff] [blame] | 74 | stage("Cleanup"){ |
| 75 | img.inside("-u root:root -v ${env.WORKSPACE}/:/operations-ui/") { |
| 76 | sh("rm -rf /operations-ui/*") |
| 77 | } |
| 78 | } |
Ivan Berezovskiy | f959aa8 | 2018-12-28 19:28:51 +0400 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | } |