blob: feed26f34536797e6b1b4d6f50e8036e2aa59313 [file] [log] [blame]
Jakub Josef83379312017-03-29 18:12:34 +02001
2/**
3 * Test salt models pipeline
4 * DEFAULT_GIT_REF
5 * DEFAULT_GIT_URL
6 * CREDENTIALS_ID
7 */
8
Jakub Josefc5a223a2017-03-01 14:40:08 +01009def common = new com.mirantis.mk.Common()
10def gerrit = new com.mirantis.mk.Gerrit()
Filip Pytloun38005aa2017-03-06 10:26:38 +010011def ssh = new com.mirantis.mk.Ssh()
12def git = new com.mirantis.mk.Git()
Jakub Josefc5a223a2017-03-01 14:40:08 +010013
Filip Pytloun19376a82017-03-07 12:29:00 +010014def gerritRef
15try {
16 gerritRef = GERRIT_REFSPEC
17} catch (MissingPropertyException e) {
18 gerritRef = null
19}
20
Jakub Josef83379312017-03-29 18:12:34 +020021def defaultGitRef, defaultGitUrl
Filip Pytloun19376a82017-03-07 12:29:00 +010022try {
Jakub Josef83379312017-03-29 18:12:34 +020023 defaultGitRef = DEFAULT_GIT_REF
24 defaultGitUrl = DEFAULT_GIT_URL
Filip Pytloun19376a82017-03-07 12:29:00 +010025} catch (MissingPropertyException e) {
Jakub Josef83379312017-03-29 18:12:34 +020026 defaultGitRef = null
27 defaultGitUrl = null
Filip Pytloun19376a82017-03-07 12:29:00 +010028}
Jakub Josef83379312017-03-29 18:12:34 +020029def checkouted = false
Jakub Joseffcb615e2017-04-10 14:34:40 +020030def merged = false
Filip Pytloun19376a82017-03-07 12:29:00 +010031
Jakub Josefc5a223a2017-03-01 14:40:08 +010032node("python") {
33 try{
34 stage("checkout") {
Filip Pytloun19376a82017-03-07 12:29:00 +010035 if (gerritRef) {
Jakub Josef83379312017-03-29 18:12:34 +020036 // job is triggered by Gerrit
Jakub Joseffcb615e2017-04-10 14:34:40 +020037 // test if change aren't already merged
38 def gerritChange = gerrit.getGerritChange(GERRIT_NAME, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID)
39 merged = gerritChange.status == "MERGED"
40 if(!merged){
41 checkouted = gerrit.gerritPatchsetCheckout ([
42 credentialsId : CREDENTIALS_ID
43 ])
44 }
Jakub Josef83379312017-03-29 18:12:34 +020045 } else if(defaultGitRef && defaultGitUrl) {
Jakub Josefe1407ac2017-03-30 14:10:19 +020046 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
Filip Pytloun19376a82017-03-07 12:29:00 +010047 }
Jakub Josef83379312017-03-29 18:12:34 +020048 if(checkouted){
49 if (fileExists('classes/system')) {
50 ssh.prepareSshAgentKey(CREDENTIALS_ID)
Filip Pytloun19376a82017-03-07 12:29:00 +010051 dir('classes/system') {
Jakub Josef83379312017-03-29 18:12:34 +020052 remoteUrl = git.getGitRemote()
53 ssh.ensureKnownHosts(remoteUrl)
Filip Pytloun19376a82017-03-07 12:29:00 +010054 }
Jakub Josef83379312017-03-29 18:12:34 +020055 ssh.agentSh("git submodule init; git submodule sync; git submodule update --recursive")
Filip Pytloun19376a82017-03-07 12:29:00 +010056 }
Jakub Joseffcb615e2017-04-10 14:34:40 +020057 }else if(!merged){
Jakub Josef5ce6a362017-03-31 13:41:17 +020058 throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
Filip Pytloun38005aa2017-03-06 10:26:38 +010059 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010060 }
61 stage("test") {
Jakub Joseffcb615e2017-04-10 14:34:40 +020062 if(merged){
63 common.successMsg("Gerrit change is already merged, no need to test them")
64 }else{
65 if(checkouted){
66 timeout(1440) {
67 wrap([$class: 'AnsiColorBuildWrapper']) {
68 sh("make test")
69 }
Jakub Josef83379312017-03-29 18:12:34 +020070 }
Filip Pytloun3f3829d2017-03-06 12:13:14 +010071 }
Jakub Josefc5a223a2017-03-01 14:40:08 +010072 }
73 }
74 } catch (Throwable e) {
75 // If there was an error or exception thrown, the build failed
76 currentBuild.result = "FAILURE"
77 throw e
78 } finally {
79 common.sendNotification(currentBuild.result,"",["slack"])
80 }
Filip Pytloun38005aa2017-03-06 10:26:38 +010081}