source: Jenkins/tools.groovy @ 9dd31e7

arm-ehjacob/cs343-translationnew-ast-unique-expr
Last change on this file since 9dd31e7 was 9dd31e7, checked in by Thierry Delisle <tdelisle@…>, 10 months ago

Removed StageName? global as it doesn't seem to work and it's not that useful

  • Property mode set to 100644
File size: 3.5 KB
Line 
1#!groovy
2
3import groovy.transform.Field
4
5// For skipping stages
6import 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
10def BuildStage(String name, boolean run, Closure block ) {
11        echo " -------- ${name} -------- "
12        if(run) {
13                stage(name, block)
14        } else {
15                stage(name) { Utils.markStageSkippedForConditional(STAGE_NAME) }
16        }
17}
18
19//===========================================================================================================
20// Common compilation routines
21//===========================================================================================================
22def Clean() {
23        BuildStage('Cleanup', true) {
24                // clean the build by wipping the build directory
25                dir(BuildDir) {
26                        deleteDir()
27                }
28        }
29}
30
31def Checkout(commitHash = null) {
32        BuildStage('Checkout', true) {
33                //checkout the source code and clean the repo
34                if(commitHash) {
35                        echo "Checking out commit <${commitHash}>"
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                        ])
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                }
46        }
47}
48
49//===========================================================================================================
50//Routine responsible of sending the email notification once the build is completed
51//===========================================================================================================
52@NonCPS
53def SplitLines(String text) {
54        def list = []
55
56        text.eachLine {
57                list += it
58        }
59
60        return list
61}
62
63PrevGitOldRef = ''
64PrevGitNewRef = ''
65def GitLogMessage(String oldRef = '', String newRef = '') {
66        if (!oldRef) { if(!PrevGitOldRef) { return "\nERROR retrieveing current git information!\n"  } else { oldRef = PrevGitOldRef } }
67        if (!newRef) { if(!PrevGitNewRef) { return "\nERROR retrieveing previous git information!\n" } else { newRef = PrevGitNewRef } }
68
69        def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim()
70        def revList = SplitLines( revText )
71
72        def gitUpdate = ""
73        revList.each { rev ->
74                def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
75                gitUpdate = gitUpdate + "       via  ${rev} (${type})"
76        }
77
78        def rev = oldRef
79        def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
80        gitUpdate = gitUpdate + "      from  ${rev} (${type})"
81
82        def gitLog    = sh(returnStdout: true, script: "git rev-list --format=short ${oldRef}...${newRef}").trim()
83
84        def gitDiff   = sh(returnStdout: true, script: "git diff --stat --color ${newRef} ${oldRef}").trim()
85        gitDiff = gitDiff.replace('[32m', '<span style="color: #00AA00;">')
86        gitDiff = gitDiff.replace('[31m', '<span style="color: #AA0000;">')
87        gitDiff = gitDiff.replace('[m', '</span>')
88
89        PrevGitOldRef = oldRef
90        PrevGitNewRef = newRef
91
92        return """
93<pre>
94The branch ${env.BRANCH_NAME} has been updated.
95${gitUpdate}
96</pre>
97
98<p>Check console output at ${env.BUILD_URL} to view the results.</p>
99
100<p>- Status --------------------------------------------------------------</p>
101
102<p>BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}</p>
103
104<p>- Log -----------------------------------------------------------------</p>
105
106<pre>
107${gitLog}
108</pre>
109
110<p>-----------------------------------------------------------------------</p>
111<pre>
112Summary of changes:
113${gitDiff}
114</pre>
115"""
116}
117
118return this;
Note: See TracBrowser for help on using the repository browser.