source: Jenkins/tools.groovy @ d4e338f

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d4e338f was d4e338f, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Fixed how GitLogMessage? saves results

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