blob: acf2a6ed0ef9e2762ff1137026f5f3d4a9c0f7c5 [file] [log] [blame]
Jakub Josefd75c1d52017-03-15 18:06:03 +01001/**
2* Groovy code testing pipeline
3* CREDENTIALS_ID - gerrit credentials id
4* GRADLE_IMAGE - gradle image name
5* GRADLE_CMD - command(s) for gradle
6*
7**/
8
9gerrit = new com.mirantis.mk.Gerrit()
10common = new com.mirantis.mk.Common()
11
Jakub Josef83379312017-03-29 18:12:34 +020012def defaultGitRef, defaultGitUrl
13try {
14 defaultGitRef = DEFAULT_GIT_REF
15 defaultGitUrl = DEFAULT_GIT_URL
16} catch (MissingPropertyException e) {
17 defaultGitRef = null
18 defaultGitUrl = null
19}
20def checkouted = false
21
Jakub Josefd75c1d52017-03-15 18:06:03 +010022node("docker"){
23 try {
24 stage ('Checkout source code'){
Jakub Josef83379312017-03-29 18:12:34 +020025 if (gerritRef) {
26 // job is triggered by Gerrit
27 checkouted = gerrit.gerritPatchsetCheckout ([
28 credentialsId : CREDENTIALS_ID
Jakub Josefd75c1d52017-03-15 18:06:03 +010029 ])
Jakub Josef83379312017-03-29 18:12:34 +020030 } else if(defaultGitRef && defaultGitUrl) {
31 checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "master", CREDENTIALS_ID)
32 }
33 if(!checkouted){
34 common.errorMsg("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
35 }
Jakub Josefd75c1d52017-03-15 18:06:03 +010036 }
37 stage ('Run Codenarc tests'){
Jakub Josef83379312017-03-29 18:12:34 +020038 if(checkouted){
39 def workspace = common.getWorkspace()
40 def jenkinsUID = common.getJenkinsUid()
41 def jenkinsGID = common.getJenkinsGid()
42 def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw -u ${jenkinsUID}:${jenkinsGID} ${GRADLE_IMAGE} ${GRADLE_CMD}", returnStdout: true).trim()
43 // Compilation failure doesn't fail the build
44 // Check gradle output explicitly
45 common.infoMsg(gradle_report)
46 if ( gradle_report =~ /Compilation failed/ ) {
47 throw new Exception("COMPILATION FAILED!")
48 }
Jakub Josefd75c1d52017-03-15 18:06:03 +010049 }
50 }
51
52 } catch (Throwable e) {
53 currentBuild.result = 'FAILURE'
Jakub Josef97e09572017-03-22 13:59:02 +010054 try{
55 def errLog = readFile('build/reports/codenarc/main.txt')
56 if(errLog){
57 common.errorMsg("Error log: ${errLog}")
58 }
59 }catch(ex){}
Jakub Josefd75c1d52017-03-15 18:06:03 +010060 throw e
61 } finally {
62 // send notification
63 common.sendNotification(currentBuild.result, "" ,["slack"])
64 }
65}