Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Jenkinsfile

    rb94206b rd56c05d0  
    22
    33//===========================================================================================================
    4 // Main compilation routines
     4// Main compilation routine
    55//===========================================================================================================
    66//Compilation script is done here but environnement set-up and error handling is done in main loop
    7 def cfa_build(boolean full_build, String flags) {
     7def cfa_build(boolean full_build) {
    88        build_stage 'Checkout'
    99                def install_dir = pwd tmp: true
     
    2323                //escapes the sandbox
    2424                //Also specify the compiler by hand
    25                 sh "./configure CXX=${currentCC.cpp_cc} CXXFLAGS=${flags} CFAFLAGS=${flags} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
     25                sh "./configure CXX=${currentCC.cpp_cc} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
    2626
    2727                //Compile the project
     
    8383}
    8484
     85def push_build() {
     86        //Don't use the build_stage function which outputs the compiler
     87        stage 'Push'
     88
     89                status_prefix = 'Push'
     90
     91                def out_dir = pwd tmp: true
     92                sh "mkdir -p ${out_dir}"
     93
     94                //parse git logs to find what changed
     95                sh "git remote > ${out_dir}/GIT_REMOTE"
     96                git_remote = readFile("${out_dir}/GIT_REMOTE")
     97                remoteDoLangExists = git_remote.contains("DoLang")
     98
     99                if( !remoteDoLangExists ) {
     100                        sh 'git remote add DoLang git@gitlab.do-lang.org:internal/cfa-cc.git'
     101                }
     102
     103                sh "git push DoLang ${gitRefNewValue}:master"
     104}
     105
    85106//===========================================================================================================
    86107// Helper classes/variables/routines to make the status and stage name easier to use
     
    134155node ('master'){
    135156
    136         boolean bIsFullBuild
     157        boolean doPromoteBuild2DoLang
    137158        def err = null
    138159        def log_needed = false
     
    155176                                                  defaultValue: false,                                          \
    156177                                                  description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \
    157                                                   name: 'isFullBuild'                                   \
    158                                                 ],                                                              \
    159                                                 [$class: 'ChoiceParameterDefinition',                           \
    160                                                   choices: '64-bit\n32-bit',                                    \
    161                                                   defaultValue: '64-bit',                                       \
    162                                                   description: 'The architecture to use for compilation',       \
    163                                                   name: 'buildArchitecture'                                     \
    164                                                 ]]                                                              \
     178                                                  name: 'promoteBuild2DoLang'                           \
     179                                                ]]                                                                      \
    165180                                        ]])
    166181
    167                                 bIsFullBuild = isFullBuild == 'true'
    168                                 architectureFlag = buildArchitecture == '64-bit' ? '-m64' : (buildArchitecture == '32-bit' ? '-m32' : 'ERROR')
    169 
    170                                 echo "FULL BUILD = ${isFullBuild}\nArchitecture = ${buildArchitecture} (flag ${architectureFlag})"
     182                                doPromoteBuild2DoLang = promoteBuild2DoLang == 'true'
     183
     184                                echo "FULL BUILD = ${doPromoteBuild2DoLang}"
    171185
    172186                                //Compile using gcc-4.9
    173187                                currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
    174                                 cfa_build(bIsFullBuild, architectureFlag)
     188                                cfa_build(doPromoteBuild2DoLang)
    175189
    176190                                //Compile latex documentation
    177191                                doc_build()
    178192
    179                                 if( bIsFullBuild ) {
     193                                if( doPromoteBuild2DoLang ) {
    180194                                        //Compile using gcc-5
    181195                                        currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
    182                                         cfa_build(true, architectureFlag)
     196                                        cfa_build(true)
    183197
    184198                                        //Compile using gcc-4.9
    185199                                        currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
    186                                         cfa_build(true, architectureFlag)
     200                                        cfa_build(true)
     201
     202                                        //Push latest changes to do-lang repo
     203                                        push_build()
    187204                                }
    188205                        }
     
    204221
    205222        finally {
    206                 echo 'Build Completed'
    207 
    208                 //Send email with final results if this is not a full build
    209                 if( !bIsFullBuild ) {
    210                         echo 'Notifying users of result'
    211                         email(currentBuild.result, log_needed)
    212                 }
     223                //Send email with final results
     224                notify_result(doPromoteBuild2DoLang, err, currentBuild.result, log_needed)
    213225
    214226                /* Must re-throw exception to propagate error */
     
    222234//Routine responsible of sending the email notification once the build is completed
    223235//===========================================================================================================
     236def notify_result(boolean promote, Exception err, String status, boolean log) {
     237        echo 'Build completed, sending result notification'
     238        if(promote)     {
     239                if( err ) {
     240                        promote_email(status)
     241                }
     242        }
     243        else {
     244                email(status, log)
     245        }
     246}
     247
     248//Email notification on a full build failure
     249def promote_email(String status) {
     250        //Since tokenizer doesn't work, figure stuff out from the environnement variables and command line
     251        //Configurations for email format
     252        def email_subject = "[cforall git][PROMOTE - FAILURE]"
     253        def email_body = """This is an automated email from the Jenkins build machine. It was
     254generated because of a git hooks/post-receive script following
     255a ref change was pushed to the repository containing
     256the project "UNNAMED PROJECT".
     257
     258Check console output at ${env.BUILD_URL} to view the results.
     259
     260- Status --------------------------------------------------------------
     261
     262PROMOTE FAILURE - ${status}
     263"""
     264
     265        def email_to = "pabuhr@uwaterloo.ca, rschlunt@uwaterloo.ca, a3moss@uwaterloo.ca, tdelisle@uwaterloo.ca, brice.dobry@huawei.com"
     266
     267        //send email notification
     268        emailext body: email_body, subject: email_subject, to: email_to, attachLog: true
     269}
     270
    224271//Standard build email notification
    225272def email(String status, boolean log) {
Note: See TracChangeset for help on using the changeset viewer.