Changeset 5b8413b4 for Jenkinsfile


Ignore:
Timestamp:
Aug 17, 2018, 2:45:09 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:
939fd39
Parents:
0fd5003
Message:

More Jenkinsfile cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Jenkinsfile

    r0fd5003 r5b8413b4  
    66node ('master'){
    77
     8        // Globals
     9        BuildDir  = pwd tmp: true
     10        SrcDir    = pwd tmp: false
     11        Settings  = null
     12        StageName = ''
     13
     14        // Local variables
    815        def err = null
    916        def log_needed = false
    10 
    11         Settings = null
    12 
    13         stage_name         = ''
    14 
    15         gitRefOldValue = ''
    16         gitRefNewValue = ''
    17 
    18         builddir = pwd tmp: true
    19         srcdir   = pwd tmp: false
    2017
    2118        currentBuild.result = "SUCCESS"
     
    6158
    6259                //Store the result of the build log
    63                 currentBuild.result = "${stage_name} FAILURE".trim()
     60                currentBuild.result = "${StageName} FAILURE".trim()
    6461        }
    6562
     
    7774                        throw err
    7875                }
     76        }
     77}
     78
     79//===========================================================================================================
     80// Main compilation routines
     81//===========================================================================================================
     82def clean() {
     83        build_stage('Cleanup') {
     84                // clean the build by wipping the build directory
     85                dir(BuildDir) {
     86                        deleteDir()
     87                }
     88
     89                //Clean all temporary files to make sure no artifacts of the previous build remain
     90                sh 'git clean -fdx'
     91
     92                //Reset the git repo so no local changes persist
     93                sh 'git reset --hard'
     94        }
     95}
     96
     97//Compilation script is done here but environnement set-up and error handling is done in main loop
     98def checkout() {
     99        build_stage('Checkout') {
     100                //checkout the source code and clean the repo
     101                checkout scm
     102        }
     103}
     104
     105def build() {
     106        build_stage('Build') {
     107                // Build outside of the src tree to ease cleaning
     108                dir (BuildDir) {
     109                        //Configure the conpilation (Output is not relevant)
     110                        //Use the current directory as the installation target so nothing escapes the sandbox
     111                        //Also specify the compiler by hand
     112                        targets=""
     113                        if( Settings.RunAllTests ) {
     114                                targets="--with-target-hosts='host:debug,host:nodebug'"
     115                        } else {
     116                                targets="--with-target-hosts='host:debug'"
     117                        }
     118
     119                        sh "${SrcDir}/configure CXX=${Settings.Compiler.cpp_cc} ${Settings.Architecture.flags} ${targets} --with-backend-compiler=${Settings.Compiler.cfa_cc} --quiet"
     120
     121                        //Compile the project
     122                        sh 'make -j 8 --no-print-directory'
     123                }
     124        }
     125}
     126
     127def test() {
     128        build_stage('Test') {
     129
     130                dir (BuildDir) {
     131                        //Run the tests from the tests directory
     132                        if ( Settings.RunAllTests ) {
     133                                sh 'make --no-print-directory -C tests all-tests debug=yes'
     134                                sh 'make --no-print-directory -C tests all-tests debug=no '
     135                        }
     136                        else {
     137                                sh 'make --no-print-directory -C tests'
     138                        }
     139                }
     140        }
     141}
     142
     143def benchmark() {
     144        build_stage('Benchmark') {
     145
     146                if( !Settings.RunBenchmark ) return
     147
     148                dir (BuildDir) {
     149                        //Append bench results
     150                        sh "make --no-print-directory -C benchmark jenkins githash=${gitRefNewValue} arch=${Settings.Architecture} | tee ${SrcDir}/bench.json"
     151                }
     152        }
     153}
     154
     155def build_doc() {
     156        build_stage('Documentation') {
     157
     158                if( !Settings.BuildDocumentation ) return
     159
     160                dir ('doc/user') {
     161                        make_doc()
     162                }
     163
     164                dir ('doc/refrat') {
     165                        make_doc()
     166                }
     167        }
     168}
     169
     170def publish() {
     171        build_stage('Publish') {
     172
     173                if( !Settings.Publish ) return
     174
     175                //Then publish the results
     176                sh 'curl --silent --show-error -H \'Content-Type: application/json\' --data @bench.json https://cforall.uwaterloo.ca:8082/jenkins/publish > /dev/null || true'
     177        }
     178}
     179
     180//===========================================================================================================
     181//Routine responsible of sending the email notification once the build is completed
     182//===========================================================================================================
     183def gitBranchUpdate(String gitRefOldValue, String gitRefNewValue) {
     184        def update = ""
     185        sh "git rev-list ${gitRefOldValue}..${gitRefNewValue} > GIT_LOG";
     186        readFile('GIT_LOG').eachLine { rev ->
     187                sh "git cat-file -t ${rev} > GIT_TYPE"
     188                def type = readFile('GIT_TYPE')
     189
     190                update += "       via  ${rev} (${type})\n"
     191        }
     192        def rev = gitRefOldValue
     193        sh "git cat-file -t ${rev} > GIT_TYPE"
     194        def type = readFile('GIT_TYPE')
     195
     196        update += "      from  ${rev} (${type})\n"
     197        return update
     198
     199        def output=readFile('result').trim()
     200        echo "output=$output";
     201}
     202
     203//Standard build email notification
     204def email(String status, boolean log, boolean bIsSandbox) {
     205        //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
     206        //Configurations for email format
     207        def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
     208
     209        def gitLog = 'Error retrieving git logs'
     210        def gitDiff = 'Error retrieving git diff'
     211        def gitUpdate = 'Error retrieving update'
     212
     213        try {
     214                final scmVars = checkout(scm)
     215
     216                gitUpdate = gitBranchUpdate(scmVars.GIT_PREVIOUS_COMMIT, scmVars.GIT_COMMIT)
     217
     218                sh "git rev-list --format=short ${scmVars.GIT_PREVIOUS_COMMIT}...${scmVars.GIT_COMMIT} > ${BuildDir}/GIT_LOG"
     219                gitLog = readFile("${BuildDir}/GIT_LOG")
     220
     221                sh "git diff --stat ${scmVars.GIT_COMMIT} ${scmVars.GIT_PREVIOUS_COMMIT} > ${BuildDir}/GIT_DIFF"
     222                gitDiff = readFile("${BuildDir}/GIT_DIFF")
     223        }
     224        catch (Exception error) {
     225                echo error.toString()
     226                echo error.getMessage()
     227        }
     228
     229        def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
     230        def email_body = """This is an automated email from the Jenkins build machine. It was
     231generated because of a git hooks/post-receive script following
     232a ref change was pushed to the repository containing
     233the project "UNNAMED PROJECT".
     234
     235The branch ${env.BRANCH_NAME} has been updated.
     236${gitUpdate}
     237
     238Check console output at ${env.BUILD_URL} to view the results.
     239
     240- Status --------------------------------------------------------------
     241
     242BUILD# ${env.BUILD_NUMBER} - ${status}
     243
     244- Log -----------------------------------------------------------------
     245${gitLog}
     246-----------------------------------------------------------------------
     247Summary of changes:
     248${gitDiff}
     249"""
     250
     251        def email_to = "cforall@lists.uwaterloo.ca"
     252
     253        if( !bIsSandbox ) {
     254                //send email notification
     255                emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
     256        } else {
     257                echo "Would send email to: ${email_to}"
     258                echo "With title: ${email_subject}"
     259                echo "Content: \n${email_body}"
    79260        }
    80261}
     
    224405
    225406def build_stage(String name, Closure block ) {
    226         stage_name = name
     407        StageName = name
    227408        stage(name, block)
     409        echo " -------- ${StageName} -------- "
    228410}
    229411
     
    247429        }
    248430}
    249 
    250 //===========================================================================================================
    251 // Main compilation routines
    252 //===========================================================================================================
    253 def clean() {
    254         build_stage('Cleanup') {
    255                 // clean the build by wipping the build directory
    256                 dir(builddir) {
    257                         deleteDir()
    258                 }
    259 
    260                 //Clean all temporary files to make sure no artifacts of the previous build remain
    261                 sh 'git clean -fdqx'
    262 
    263                 //Reset the git repo so no local changes persist
    264                 sh 'git reset --hard'
    265         }
    266 }
    267 
    268 //Compilation script is done here but environnement set-up and error handling is done in main loop
    269 def checkout() {
    270         build_stage('Checkout') {
    271                 //checkout the source code and clean the repo
    272                 checkout scm
    273         }
    274 }
    275 
    276 def build() {
    277         build_stage('Build') {
    278                 // Build outside of the src tree to ease cleaning
    279                 dir (builddir) {
    280                         //Configure the conpilation (Output is not relevant)
    281                         //Use the current directory as the installation target so nothing escapes the sandbox
    282                         //Also specify the compiler by hand
    283                         targets=""
    284                         if( Settings.RunAllTests ) {
    285                                 targets="--with-target-hosts='host:debug,host:nodebug'"
    286                         } else {
    287                                 targets="--with-target-hosts='host:debug'"
    288                         }
    289 
    290                         sh "${srcdir}/configure CXX=${Settings.Compiler.cpp_cc} ${Settings.Architecture.flags} ${targets} --with-backend-compiler=${Settings.Compiler.cfa_cc} --quiet"
    291 
    292                         //Compile the project
    293                         sh 'make -j 8 --no-print-directory'
    294                 }
    295         }
    296 }
    297 
    298 def test() {
    299         build_stage('Test') {
    300 
    301                 dir (builddir) {
    302                         //Run the tests from the tests directory
    303                         if ( Settings.RunAllTests ) {
    304                                 sh 'make --no-print-directory -C tests all-tests debug=yes'
    305                                 sh 'make --no-print-directory -C tests all-tests debug=no '
    306                         }
    307                         else {
    308                                 sh 'make --no-print-directory -C tests'
    309                         }
    310                 }
    311         }
    312 }
    313 
    314 def benchmark() {
    315         build_stage('Benchmark') {
    316 
    317                 if( !Settings.RunBenchmark ) return
    318 
    319                 dir (builddir) {
    320                         //Append bench results
    321                         sh "make --no-print-directory -C benchmark jenkins githash=${gitRefNewValue} arch=${Settings.Architecture} | tee ${srcdir}/bench.json"
    322                 }
    323         }
    324 }
    325 
    326 def build_doc() {
    327         build_stage('Documentation') {
    328 
    329                 if( !Settings.BuildDocumentation ) return
    330 
    331                 dir ('doc/user') {
    332                         make_doc()
    333                 }
    334 
    335                 dir ('doc/refrat') {
    336                         make_doc()
    337                 }
    338         }
    339 }
    340 
    341 def publish() {
    342         build_stage('Publish') {
    343 
    344                 if( !Settings.Publish ) return
    345 
    346                 //Then publish the results
    347                 sh 'curl --silent --show-error -H \'Content-Type: application/json\' --data @bench.json https://cforall.uwaterloo.ca:8082/jenkins/publish > /dev/null || true'
    348         }
    349 }
    350 
    351 //===========================================================================================================
    352 //Routine responsible of sending the email notification once the build is completed
    353 //===========================================================================================================
    354 def gitBranchUpdate(String gitRefOldValue, String gitRefNewValue) {
    355         def update = ""
    356         sh "git rev-list ${gitRefOldValue}..${gitRefNewValue} > GIT_LOG";
    357         readFile('GIT_LOG').eachLine { rev ->
    358                 sh "git cat-file -t ${rev} > GIT_TYPE"
    359                 def type = readFile('GIT_TYPE')
    360 
    361                 update += "       via  ${rev} (${type})\n"
    362         }
    363         def rev = gitRefOldValue
    364         sh "git cat-file -t ${rev} > GIT_TYPE"
    365         def type = readFile('GIT_TYPE')
    366 
    367         update += "      from  ${rev} (${type})\n"
    368         return update
    369 
    370         def output=readFile('result').trim()
    371         echo "output=$output";
    372 }
    373 
    374 //Standard build email notification
    375 def email(String status, boolean log, boolean bIsSandbox) {
    376         //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
    377         //Configurations for email format
    378         def project_name = (env.JOB_NAME =~ /(.+)\/.+/)[0][1].toLowerCase()
    379 
    380         def gitLog = 'Error retrieving git logs'
    381         def gitDiff = 'Error retrieving git diff'
    382         def gitUpdate = 'Error retrieving update'
    383 
    384         try {
    385                 final scmVars = checkout(scm)
    386 
    387                 gitUpdate = gitBranchUpdate(scmVars.GIT_PREVIOUS_COMMIT, scmVars.GIT_COMMIT)
    388 
    389                 sh "git rev-list --format=short ${scmVars.GIT_PREVIOUS_COMMIT}...${scmVars.GIT_COMMIT} > GIT_LOG"
    390                 gitLog = readFile('GIT_LOG')
    391 
    392                 sh "git diff --stat ${scmVars.GIT_COMMIT} ${scmVars.GIT_PREVIOUS_COMMIT} > GIT_DIFF"
    393                 gitDiff = readFile('GIT_DIFF')
    394         }
    395         catch (Exception error) {
    396                 echo error.toString()
    397                 echo error.getMessage()
    398         }
    399 
    400         def email_subject = "[${project_name} git][BUILD# ${env.BUILD_NUMBER} - ${status}] - branch ${env.BRANCH_NAME}"
    401         def email_body = """This is an automated email from the Jenkins build machine. It was
    402 generated because of a git hooks/post-receive script following
    403 a ref change was pushed to the repository containing
    404 the project "UNNAMED PROJECT".
    405 
    406 The branch ${env.BRANCH_NAME} has been updated.
    407 ${gitUpdate}
    408 
    409 Check console output at ${env.BUILD_URL} to view the results.
    410 
    411 - Status --------------------------------------------------------------
    412 
    413 BUILD# ${env.BUILD_NUMBER} - ${status}
    414 
    415 - Log -----------------------------------------------------------------
    416 ${gitLog}
    417 -----------------------------------------------------------------------
    418 Summary of changes:
    419 ${gitDiff}
    420 """
    421 
    422         def email_to = "cforall@lists.uwaterloo.ca"
    423 
    424         if( !bIsSandbox ) {
    425                 //send email notification
    426                 emailext body: email_body, subject: email_subject, to: email_to, attachLog: log
    427         } else {
    428                 echo "Would send email to: ${email_to}"
    429                 echo "With title: ${email_subject}"
    430                 echo "Content: \n${email_body}"
    431         }
    432 }
Note: See TracChangeset for help on using the changeset viewer.