[27b1ca1] | 1 | #!groovy
|
---|
| 2 |
|
---|
[d29a394] | 3 | import groovy.transform.Field
|
---|
[27b1ca1] | 4 |
|
---|
| 5 | // For skipping stages
|
---|
| 6 | import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
|
---|
| 7 |
|
---|
| 8 | // wrapper around stage declaretion to be more verbose
|
---|
| 9 | // and allow showing as skipped in the UI
|
---|
[1483a16] | 10 | def BuildStage(String name, boolean run, Closure block ) {
|
---|
[9dd31e7] | 11 | echo " -------- ${name} -------- "
|
---|
[27b1ca1] | 12 | if(run) {
|
---|
| 13 | stage(name, block)
|
---|
| 14 | } else {
|
---|
| 15 | stage(name) { Utils.markStageSkippedForConditional(STAGE_NAME) }
|
---|
| 16 | }
|
---|
[8ca82de] | 17 | }
|
---|
| 18 |
|
---|
[4011b98] | 19 | //===========================================================================================================
|
---|
| 20 | // Common compilation routines
|
---|
| 21 | //===========================================================================================================
|
---|
[6c9e0bc] | 22 | def Clean() {
|
---|
[f78ead5] | 23 | BuildStage('Cleanup', true) {
|
---|
[4011b98] | 24 | // clean the build by wipping the build directory
|
---|
| 25 | dir(BuildDir) {
|
---|
| 26 | deleteDir()
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[6c9e0bc] | 31 | def Checkout(commitHash = null) {
|
---|
[d29a394] | 32 | BuildStage('Checkout', true) {
|
---|
| 33 | //checkout the source code and clean the repo
|
---|
[68f2e42] | 34 | if(commitHash) {
|
---|
[143cbf1] | 35 | echo "Checking out commit <${commitHash}>"
|
---|
[6c0ef72] | 36 | final scmVars = checkout([$class: 'GitSCM', branches: [[name: commitHash ]],
|
---|
| 37 | userRemoteConfigs: [[
|
---|
| 38 | url: 'cforall@plg.uwaterloo.ca:software/cfa/cfa-cc',
|
---|
| 39 | credentialsId: 'git_key_aug20']]
|
---|
| 40 | ])
|
---|
[032fd93] | 41 | echo GitLogMessage(scmVars.GIT_COMMIT, scmVars.GIT_PREVIOUS_COMMIT)
|
---|
| 42 | } else {
|
---|
| 43 | final scmVars = checkout scm
|
---|
| 44 | echo GitLogMessage(scmVars.GIT_COMMIT, scmVars.GIT_PREVIOUS_COMMIT)
|
---|
| 45 | }
|
---|
[d29a394] | 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | //===========================================================================================================
|
---|
| 50 | //Routine responsible of sending the email notification once the build is completed
|
---|
| 51 | //===========================================================================================================
|
---|
| 52 | @NonCPS
|
---|
| 53 | def SplitLines(String text) {
|
---|
| 54 | def list = []
|
---|
| 55 |
|
---|
| 56 | text.eachLine {
|
---|
| 57 | list += it
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | return list
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[cc5544a] | 63 | def ConstructGitLogMessage(String oldRef, String newRef) {
|
---|
[d29a394] | 64 | def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim()
|
---|
| 65 | def revList = SplitLines( revText )
|
---|
| 66 |
|
---|
| 67 | def gitUpdate = ""
|
---|
| 68 | revList.each { rev ->
|
---|
| 69 | def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
|
---|
| 70 | gitUpdate = gitUpdate + " via ${rev} (${type})"
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | def rev = oldRef
|
---|
| 74 | def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
|
---|
| 75 | gitUpdate = gitUpdate + " from ${rev} (${type})"
|
---|
| 76 |
|
---|
| 77 | def gitLog = sh(returnStdout: true, script: "git rev-list --format=short ${oldRef}...${newRef}").trim()
|
---|
| 78 |
|
---|
| 79 | def gitDiff = sh(returnStdout: true, script: "git diff --stat --color ${newRef} ${oldRef}").trim()
|
---|
| 80 | gitDiff = gitDiff.replace('[32m', '<span style="color: #00AA00;">')
|
---|
| 81 | gitDiff = gitDiff.replace('[31m', '<span style="color: #AA0000;">')
|
---|
| 82 | gitDiff = gitDiff.replace('[m', '</span>')
|
---|
| 83 |
|
---|
| 84 | return """
|
---|
[9824500] | 85 | <p>- Changes -------------------------------------------------------------</p>
|
---|
| 86 |
|
---|
[d29a394] | 87 | <pre>
|
---|
| 88 | The branch ${env.BRANCH_NAME} has been updated.
|
---|
| 89 | ${gitUpdate}
|
---|
| 90 | </pre>
|
---|
| 91 |
|
---|
| 92 | <p>- Log -----------------------------------------------------------------</p>
|
---|
| 93 |
|
---|
| 94 | <pre>
|
---|
| 95 | ${gitLog}
|
---|
| 96 | </pre>
|
---|
| 97 |
|
---|
| 98 | <p>-----------------------------------------------------------------------</p>
|
---|
| 99 | <pre>
|
---|
| 100 | Summary of changes:
|
---|
| 101 | ${gitDiff}
|
---|
| 102 | </pre>
|
---|
| 103 | """
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[cc5544a] | 106 | EmailMessage = ''
|
---|
| 107 | def GitLogMessage(String oldRef = '', String newRef = '') {
|
---|
| 108 | if(!EmailMessage) {
|
---|
| 109 | if (!oldRef) { return "\nERROR retrieveing current git information!\n" }
|
---|
| 110 | if (!newRef) { return "\nERROR retrieveing previous git information!\n" }
|
---|
| 111 |
|
---|
| 112 | echo "Constructing new git message"
|
---|
| 113 |
|
---|
| 114 | EmailMessage = ConstructGitLogMessage(oldRef, newRef)
|
---|
| 115 | }
|
---|
| 116 | else {
|
---|
| 117 | echo "Reusing previously constructed message"
|
---|
| 118 | }
|
---|
| 119 | return EmailMessage;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[8ca82de] | 122 | return this;
|
---|