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