source: Jenkins/tools.groovy @ 9c4ad67

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

Fixed typo

  • 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 { oldRef = PrevGitOldRef } }
71        if (!newRef) { if(!PrevGitNewRef) { return "\nERROR retrieveing previous git information!\n" } else { newRef = PrevGitNewRef } }
72
73        def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim()
74        def revList = SplitLines( revText )
75
76        def gitUpdate = ""
77        revList.each { rev ->
78                def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
79                gitUpdate = gitUpdate + "       via  ${rev} (${type})"
80        }
81
82        def rev = oldRef
83        def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
84        gitUpdate = gitUpdate + "      from  ${rev} (${type})"
85
86        def gitLog    = sh(returnStdout: true, script: "git rev-list --format=short ${oldRef}...${newRef}").trim()
87
88        def gitDiff   = sh(returnStdout: true, script: "git diff --stat --color ${newRef} ${oldRef}").trim()
89        gitDiff = gitDiff.replace('[32m', '<span style="color: #00AA00;">')
90        gitDiff = gitDiff.replace('[31m', '<span style="color: #AA0000;">')
91        gitDiff = gitDiff.replace('[m', '</span>')
92
93        PrevGitOldRef = oldRef
94        PrevGitNewRef = newRef
95
96        return """
97<pre>
98The branch ${env.BRANCH_NAME} has been updated.
99${gitUpdate}
100</pre>
101
102<p>Check console output at ${env.BUILD_URL} to view the results.</p>
103
104<p>- Status --------------------------------------------------------------</p>
105
106<p>BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}</p>
107
108<p>- Log -----------------------------------------------------------------</p>
109
110<pre>
111${gitLog}
112</pre>
113
114<p>-----------------------------------------------------------------------</p>
115<pre>
116Summary of changes:
117${gitDiff}
118</pre>
119"""
120}
121
122return this;
Note: See TracBrowser for help on using the repository browser.