Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 1 | /** |
| 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 | |
| 9 | gerrit = new com.mirantis.mk.Gerrit() |
| 10 | common = new com.mirantis.mk.Common() |
| 11 | |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame^] | 12 | def defaultGitRef, defaultGitUrl |
| 13 | try { |
| 14 | defaultGitRef = DEFAULT_GIT_REF |
| 15 | defaultGitUrl = DEFAULT_GIT_URL |
| 16 | } catch (MissingPropertyException e) { |
| 17 | defaultGitRef = null |
| 18 | defaultGitUrl = null |
| 19 | } |
| 20 | def checkouted = false |
| 21 | |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 22 | node("docker"){ |
| 23 | try { |
| 24 | stage ('Checkout source code'){ |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame^] | 25 | if (gerritRef) { |
| 26 | // job is triggered by Gerrit |
| 27 | checkouted = gerrit.gerritPatchsetCheckout ([ |
| 28 | credentialsId : CREDENTIALS_ID |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 29 | ]) |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame^] | 30 | } 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 Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 36 | } |
| 37 | stage ('Run Codenarc tests'){ |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame^] | 38 | 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 Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 49 | } |
| 50 | } |
| 51 | |
| 52 | } catch (Throwable e) { |
| 53 | currentBuild.result = 'FAILURE' |
Jakub Josef | 97e0957 | 2017-03-22 13:59:02 +0100 | [diff] [blame] | 54 | try{ |
| 55 | def errLog = readFile('build/reports/codenarc/main.txt') |
| 56 | if(errLog){ |
| 57 | common.errorMsg("Error log: ${errLog}") |
| 58 | } |
| 59 | }catch(ex){} |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 60 | throw e |
| 61 | } finally { |
| 62 | // send notification |
| 63 | common.sendNotification(currentBuild.result, "" ,["slack"]) |
| 64 | } |
| 65 | } |