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 | e1407ac | 2017-03-30 14:10:19 +0200 | [diff] [blame] | 12 | def gerritRef |
| 13 | try { |
| 14 | gerritRef = GERRIT_REFSPEC |
| 15 | } catch (MissingPropertyException e) { |
| 16 | gerritRef = null |
| 17 | } |
| 18 | |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 19 | def defaultGitRef, defaultGitUrl |
| 20 | try { |
| 21 | defaultGitRef = DEFAULT_GIT_REF |
| 22 | defaultGitUrl = DEFAULT_GIT_URL |
| 23 | } catch (MissingPropertyException e) { |
| 24 | defaultGitRef = null |
| 25 | defaultGitUrl = null |
| 26 | } |
| 27 | def checkouted = false |
| 28 | |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 29 | node("docker"){ |
| 30 | try { |
| 31 | stage ('Checkout source code'){ |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 32 | if (gerritRef) { |
| 33 | // job is triggered by Gerrit |
| 34 | checkouted = gerrit.gerritPatchsetCheckout ([ |
| 35 | credentialsId : CREDENTIALS_ID |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 36 | ]) |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 37 | } else if(defaultGitRef && defaultGitUrl) { |
Jakub Josef | e1407ac | 2017-03-30 14:10:19 +0200 | [diff] [blame] | 38 | checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID) |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 39 | } |
| 40 | if(!checkouted){ |
| 41 | common.errorMsg("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null") |
| 42 | } |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 43 | } |
| 44 | stage ('Run Codenarc tests'){ |
Jakub Josef | 8337931 | 2017-03-29 18:12:34 +0200 | [diff] [blame] | 45 | if(checkouted){ |
| 46 | def workspace = common.getWorkspace() |
| 47 | def jenkinsUID = common.getJenkinsUid() |
| 48 | def jenkinsGID = common.getJenkinsGid() |
| 49 | def gradle_report = sh (script: "docker run --rm -v ${workspace}:/usr/bin/app:rw -u ${jenkinsUID}:${jenkinsGID} ${GRADLE_IMAGE} ${GRADLE_CMD}", returnStdout: true).trim() |
| 50 | // Compilation failure doesn't fail the build |
| 51 | // Check gradle output explicitly |
| 52 | common.infoMsg(gradle_report) |
| 53 | if ( gradle_report =~ /Compilation failed/ ) { |
| 54 | throw new Exception("COMPILATION FAILED!") |
| 55 | } |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
| 59 | } catch (Throwable e) { |
| 60 | currentBuild.result = 'FAILURE' |
Jakub Josef | 97e0957 | 2017-03-22 13:59:02 +0100 | [diff] [blame] | 61 | try{ |
| 62 | def errLog = readFile('build/reports/codenarc/main.txt') |
| 63 | if(errLog){ |
| 64 | common.errorMsg("Error log: ${errLog}") |
| 65 | } |
| 66 | }catch(ex){} |
Jakub Josef | d75c1d5 | 2017-03-15 18:06:03 +0100 | [diff] [blame] | 67 | throw e |
| 68 | } finally { |
| 69 | // send notification |
| 70 | common.sendNotification(currentBuild.result, "" ,["slack"]) |
| 71 | } |
| 72 | } |