blob: 1329f17fb1df6f9210cba4cfdbf265c642f5de6a [file] [log] [blame]
chnydad66d6fa2017-06-22 09:34:43 +02001
2/**
3 * Test salt models pipeline
4 * DEFAULT_GIT_REF
5 * DEFAULT_GIT_URL
6 * CREDENTIALS_ID
7 * EXTRA_FORMULAS
8 * NODE_TARGET
9 * SYSTEM_GIT_URL
10 * SYSTEM_GIT_REF
11 */
12
13def common = new com.mirantis.mk.Common()
14def gerrit = new com.mirantis.mk.Gerrit()
chnydac6092a22017-06-22 14:47:10 +020015def ssh = new com.mirantis.mk.Ssh()
chnydad66d6fa2017-06-22 09:34:43 +020016def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
17
18def defaultGitRef = DEFAULT_GIT_REF
19def defaultGitUrl = DEFAULT_GIT_URL
20
21def checkouted = false
22node("python") {
23 try{
24 stage("checkout") {
25 if(defaultGitRef != "" && defaultGitUrl != "") {
26 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
27 } else {
28 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
29 }
30 if(checkouted) {
31 if (fileExists('classes/system')) {
32 if (SYSTEM_GIT_URL == "") {
33 ssh.prepareSshAgentKey(CREDENTIALS_ID)
34 dir('classes/system') {
35 remoteUrl = git.getGitRemote()
36 ssh.ensureKnownHosts(remoteUrl)
37 }
38 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
39 } else {
40 dir('classes/system') {
41 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
42 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
43 }
44 }
45 }
46 }
47 }
48 }
49
50 stage("test node") {
51 if (checkouted) {
52 def workspace = common.getWorkspace()
53 saltModelTesting.setupAndTestNode(NODE_TARGET, EXTRA_FORMULAS, workspace)
54 }
55 }
56 } catch (Throwable e) {
57 // If there was an error or exception thrown, the build failed
58 currentBuild.result = "FAILURE"
59 throw e
60 } finally {
61 common.sendNotification(currentBuild.result,"",["slack"])
62 }
63}