source: Jenkins/tools.groovy @ cf2257f

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

Distribute not checksout a specific commit on the target node

  • Property mode set to 100644
File size: 3.0 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                final scmVars = ref ? checkout scm : checkout([$class: 'GitSCM', branches: [[name: commitHash ]]])
39
40                echo GitLogMessage(scmVars.GIT_COMMIT, scmVars.GIT_PREVIOUS_COMMIT)
41        }
42}
43
44//===========================================================================================================
45//Routine responsible of sending the email notification once the build is completed
46//===========================================================================================================
47@NonCPS
48def SplitLines(String text) {
49        def list = []
50
51        text.eachLine {
52                list += it
53        }
54
55        return list
56}
57
58def GitLogMessage(String oldRef, String newRef) {
59        def revText = sh(returnStdout: true, script: "git rev-list ${oldRef}..${newRef}").trim()
60        def revList = SplitLines( revText )
61
62        def gitUpdate = ""
63        revList.each { rev ->
64                def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
65                gitUpdate = gitUpdate + "       via  ${rev} (${type})"
66        }
67
68        def rev = oldRef
69        def type = sh(returnStdout: true, script: "git cat-file -t ${rev}").trim()
70        gitUpdate = gitUpdate + "      from  ${rev} (${type})"
71
72        def gitLog    = sh(returnStdout: true, script: "git rev-list --format=short ${oldRef}...${newRef}").trim()
73
74        def gitDiff   = sh(returnStdout: true, script: "git diff --stat --color ${newRef} ${oldRef}").trim()
75        gitDiff = gitDiff.replace('[32m', '<span style="color: #00AA00;">')
76        gitDiff = gitDiff.replace('[31m', '<span style="color: #AA0000;">')
77        gitDiff = gitDiff.replace('[m', '</span>')
78
79        return """
80<pre>
81The branch ${env.BRANCH_NAME} has been updated.
82${gitUpdate}
83</pre>
84
85<p>Check console output at ${env.BUILD_URL} to view the results.</p>
86
87<p>- Status --------------------------------------------------------------</p>
88
89<p>BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}</p>
90
91<p>- Log -----------------------------------------------------------------</p>
92
93<pre>
94${gitLog}
95</pre>
96
97<p>-----------------------------------------------------------------------</p>
98<pre>
99Summary of changes:
100${gitDiff}
101</pre>
102"""
103}
104
105return this;
Note: See TracBrowser for help on using the repository browser.