blob: 8ec39361d4e92376905838adc9387a91df7134a0 [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()
15def saltModelTesting = new com.mirantis.mk.SaltModelTesting()
16
17def defaultGitRef = DEFAULT_GIT_REF
18def defaultGitUrl = DEFAULT_GIT_URL
19
20def checkouted = false
21node("python") {
22 try{
23 stage("checkout") {
24 if(defaultGitRef != "" && defaultGitUrl != "") {
25 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
26 } else {
27 throw new Exception("Cannot checkout gerrit patchset, DEFAULT_GIT_URL or DEFAULT_GIT_REF is null")
28 }
29 if(checkouted) {
30 if (fileExists('classes/system')) {
31 if (SYSTEM_GIT_URL == "") {
32 ssh.prepareSshAgentKey(CREDENTIALS_ID)
33 dir('classes/system') {
34 remoteUrl = git.getGitRemote()
35 ssh.ensureKnownHosts(remoteUrl)
36 }
37 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
38 } else {
39 dir('classes/system') {
40 if (!gerrit.gerritPatchsetCheckout(SYSTEM_GIT_URL, SYSTEM_GIT_REF, "HEAD", CREDENTIALS_ID)) {
41 common.errorMsg("Failed to obtain system reclass with url: ${SYSTEM_GIT_URL} and ${SYSTEM_GIT_REF}")
42 }
43 }
44 }
45 }
46 }
47 }
48
49 stage("test node") {
50 if (checkouted) {
51 def workspace = common.getWorkspace()
52 saltModelTesting.setupAndTestNode(NODE_TARGET, EXTRA_FORMULAS, workspace)
53 }
54 }
55 } catch (Throwable e) {
56 // If there was an error or exception thrown, the build failed
57 currentBuild.result = "FAILURE"
58 throw e
59 } finally {
60 common.sendNotification(currentBuild.result,"",["slack"])
61 }
62}