source: Jenkins/tools.groovy @ d4e338f

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

Fixed how GitLogMessage? saves results

  • Property mode set to 100644
File size: 3.6 KB
Line 
1#!groovy
2
3import groovy.transform.Field
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
13def BuildStage(String name, boolean run, Closure block ) {
14        StageName = name
15        echo " -------- ${StageName} -------- "
16        if(run) {
17                stage(name, block)
18        } else {
19                stage(name) { Utils.markStageSkippedForConditional(STAGE_NAME) }
20        }
21}
22
23//===========================================================================================================
24// Common compilation routines
25//===========================================================================================================
26def Clean() {
27        BuildStage('Cleanup', true) {
28                // clean the build by wipping the build directory
29                dir(BuildDir) {
30                        deleteDir()
31                }
32        }
33}
34
35def Checkout(commitHash = null) {
36        BuildStage('Checkout', true) {
37                //checkout the source code and clean the repo
38                if(commitHash) {
39                        echo "Checking out commit <${commitHash}>"
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                        ])
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                }
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
67PrevGitOldRef = ''
68PrevGitNewRef = ''
69def GitLogMessage(String oldRef = '', String newRef = '') {
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 } }
72
73        PrevGitOldRef = oldRef
74        PrevGitNewRef = newRef
75
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
96        PrevGitOldRef = oldRef
97        PrevGitNewRef = newRef
98
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
125return this;
Note: See TracBrowser for help on using the repository browser.