blob: 45404cb587d311b780f997eaa28252e45cd1ab7f [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
12node("docker"){
13 try {
14 stage ('Checkout source code'){
15 gerrit.gerritPatchsetCheckout ([
16 credentialsId : CREDENTIALS_ID,
Jakub Josef575d50b2017-03-23 17:55:41 +010017 withWipeOut : true,
18 gerritRefSpec: GERRIT_REFSPEC,
19 gerritName: GERRIT_NAME,
20 gerritHost: GERRIT_HOST,
21 gerritPort: GERRIT_PORT,
22 gerritProject: GERRIT_PROJECT,
23 gerritBranch: GERRIT_BRANCH,
Jakub Josefd75c1d52017-03-15 18:06:03 +010024 ])
25 }
26 stage ('Run Codenarc tests'){
27 def workspace = common.getWorkspace()
Jakub Josef1ee1e4a2017-03-23 12:36:25 +010028 def jenkinsUID = common.getJenkinsUid()
29 def jenkinsGID = common.getJenkinsGid()
30 def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw -u ${jenkinsUID}:${jenkinsGID} ${GRADLE_IMAGE} ${GRADLE_CMD}", returnStdout: true).trim()
Jakub Josefd75c1d52017-03-15 18:06:03 +010031 // Compilation failure doesn't fail the build
32 // Check gradle output explicitly
33 common.infoMsg(gradle_report)
34 if ( gradle_report =~ /Compilation failed/ ) {
35 throw new Exception("COMPILATION FAILED!")
36 }
37 }
38
39 } catch (Throwable e) {
40 currentBuild.result = 'FAILURE'
Jakub Josef97e09572017-03-22 13:59:02 +010041 try{
42 def errLog = readFile('build/reports/codenarc/main.txt')
43 if(errLog){
44 common.errorMsg("Error log: ${errLog}")
45 }
46 }catch(ex){}
Jakub Josefd75c1d52017-03-15 18:06:03 +010047 throw e
48 } finally {
49 // send notification
50 common.sendNotification(currentBuild.result, "" ,["slack"])
51 }
52}