Changeset a336d46 for Jenkinsfile


Ignore:
Timestamp:
Aug 17, 2018, 3:57:44 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
7efec15
Parents:
e57ebb5
Message:

Tentative to improve handling of git changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Jenkinsfile

    re57ebb5 ra336d46  
    6464                //Send email with final results if this is not a full build
    6565                if( Settings && !Settings.Silent ) {
    66                         echo 'Notifying users of result'
    6766                        email(log_needed, Settings.IsSandbox)
    6867                }
     
    9392        build_stage('Checkout') {
    9493                //checkout the source code and clean the repo
    95                 checkout scm
    96 
    97                 def changeLogSets = currentBuild.changeSets
    98                 for (int i = 0; i < changeLogSets.size(); i++) {
    99                         def entries = changeLogSets[i].items
    100                         for (int j = 0; j < entries.length; j++) {
    101                                 def entry = entries[j]
    102                                 echo "${entry.commitId} by ${entry.author} on ${new Date(entry.timestamp)}: ${entry.msg}"
    103                                 def files = new ArrayList(entry.affectedFiles)
    104                                 for (int k = 0; k < files.size(); k++) {
    105                                         def file = files[k]
    106                                         echo "  ${file.editType.name} ${file.path}"
    107                                 }
    108                         }
    109                 }
    110 
    111                 echo """This is an automated email from the Jenkins build machine. It was
    112 generated because of a git hooks/post-receive script following
    113 a ref change was pushed to the repository containing
    114 the project "UNNAMED PROJECT".
    115 
    116 The branch ${env.BRANCH_NAME} has been updated.
    117 
    118 
    119 Check console output at ${env.BUILD_URL} to view the results.
    120 
    121 - Status --------------------------------------------------------------
    122 
    123 BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}
    124 
    125 - Log -----------------------------------------------------------------
    126 
    127 -----------------------------------------------------------------------
    128 Summary of changes:
    129 
    130 """
     94                final scmVars = checkout scm
     95                Settings.GitNewRef = scmVars.GIT_COMMIT
     96                Settings.GitOldRef = scmVars.GIT_PREVIOUS_COMMIT
     97
     98                echo GitLogMessage()
    13199        }
    132100}
     
    210178//Routine responsible of sending the email notification once the build is completed
    211179//===========================================================================================================
    212 def gitBranchUpdate(String gitRefOldValue, String gitRefNewValue) {
     180def gitUpdate(String gitRefOldValue, String gitRefNewValue) {
    213181        def update = ""
    214182        sh "git rev-list ${gitRefOldValue}..${gitRefNewValue} > GIT_LOG";
     
    225193        update += "      from  ${rev} (${type})\n"
    226194        return update
    227 
    228         def output=readFile('result').trim()
    229         echo "output=$output";
     195}
     196
     197def gitLog(String gitRefOldValue, String gitRefNewValue) {
     198        sh "git rev-list --format=short ${oldRef}...${newRef} > ${BuildDir}/GIT_LOG"
     199        return readFile("${BuildDir}/GIT_LOG")
     200}
     201
     202def gitDiff(String gitRefOldValue, String gitRefNewValue) {
     203        sh "git diff --stat ${newRef} ${oldRef} > ${BuildDir}/GIT_DIFF"
     204        return readFile("${BuildDir}/GIT_DIFF")
     205}
     206
     207def GitLogMessage() {
     208        if (!Settings || !Settings.GitOldRef || !Settings.GitNewRef) return "\nERROR retrieveing git information!\n"
     209
     210        return """
     211The branch ${env.BRANCH_NAME} has been updated.
     212${gitUpdate(Settings.GitOldRef, Settings.GitNewRef)}
     213
     214Check console output at ${env.BUILD_URL} to view the results.
     215
     216- Status --------------------------------------------------------------
     217
     218BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}
     219
     220- Log -----------------------------------------------------------------
     221${gitLog(Settings.GitOldRef, Settings.GitNewRef)}
     222-----------------------------------------------------------------------
     223Summary of changes:
     224${gitDiff(Settings.GitOldRef, Settings.GitNewRef)}
     225"""
    230226}
    231227
     
    234230        //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
    235231        //Configurations for email format
     232        echo 'Notifying users of result'
     233
    236234        def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
    237 
    238         def gitLog = 'Error retrieving git logs'
    239         def gitDiff = 'Error retrieving git diff'
    240         def gitUpdate = 'Error retrieving update'
    241 
    242         try {
    243                 final scmVars = checkout(scm)
    244 
    245                 gitUpdate = gitBranchUpdate(scmVars.GIT_PREVIOUS_COMMIT, scmVars.GIT_COMMIT)
    246 
    247                 sh "git rev-list --format=short ${scmVars.GIT_PREVIOUS_COMMIT}...${scmVars.GIT_COMMIT} > ${BuildDir}/GIT_LOG"
    248                 gitLog = readFile("${BuildDir}/GIT_LOG")
    249 
    250                 sh "git diff --stat ${scmVars.GIT_COMMIT} ${scmVars.GIT_PREVIOUS_COMMIT} > ${BuildDir}/GIT_DIFF"
    251                 gitDiff = readFile("${BuildDir}/GIT_DIFF")
    252         }
    253         catch (Exception error) {
    254                 echo error.toString()
    255                 echo error.getMessage()
    256         }
    257 
    258235        def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}] - branch ${env.BRANCH_NAME}"
    259236        def email_body = """This is an automated email from the Jenkins build machine. It was
    260237generated because of a git hooks/post-receive script following
    261 a ref change was pushed to the repository containing
    262 the project "UNNAMED PROJECT".
    263 
    264 The branch ${env.BRANCH_NAME} has been updated.
    265 ${gitUpdate}
    266 
    267 Check console output at ${env.BUILD_URL} to view the results.
    268 
    269 - Status --------------------------------------------------------------
    270 
    271 BUILD# ${env.BUILD_NUMBER} - ${currentBuild.result}
    272 
    273 - Log -----------------------------------------------------------------
    274 ${gitLog}
    275 -----------------------------------------------------------------------
    276 Summary of changes:
    277 ${gitDiff}
    278 """
     238a ref change which was pushed to the Cforall repository.
     239""" + GitLogMessage()
    279240
    280241        def email_to = "cforall@lists.uwaterloo.ca"
     
    329290        public final String DescShort
    330291
     292        public String GitNewRef
     293        public String GitOldRef
     294
    331295        BuildSettings(java.util.Collections$UnmodifiableMap param, String branch) {
    332296                switch( param.Compiler ) {
     
    377341Silent                  : ${ this.Silent.toString() }
    378342"""
     343
     344                this.GitNewRef = ''
     345                this.GitOldRef = ''
    379346        }
    380347}
Note: See TracChangeset for help on using the changeset viewer.