Changeset 95fdb0a for Jenkinsfile


Ignore:
Timestamp:
Feb 22, 2017, 1:19:43 PM (7 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, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
bd34bcf5
Parents:
f31cb3e
Message:

Refectored jenkins file to be much more modular

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Jenkinsfile

    rf31cb3e r95fdb0a  
    1010        def log_needed = false
    1111
    12         bIsFullBuild = false
    13         architectureFlag = ''
    14         status_prefix = ''
     12        compiler                = compiler_from_params()
     13        architecture    = architecture_from_params()
     14       
     15        do_alltests             = param_allTests        .toBoolean()
     16        do_benchmark    = param_benchmark .toBoolean()
     17        do_doc          = param_doc     .toBoolean()
     18        do_publish
    1519
    1620        currentBuild.result = "SUCCESS"
    1721
    1822        try {
    19                 //Prevent the build from exceeding 60 minutes
    20                 timeout(60) {
    21 
    22                         //Wrap build to add timestamp to command line
    23                         wrap([$class: 'TimestamperBuildWrapper']) {
     23                //Wrap build to add timestamp to command line
     24                wrap([$class: 'TimestamperBuildWrapper']) {
     25
     26                        //Prevent the build from exceeding 60 minutes
     27                        timeout(60) {
     28
     29                                notify()
    2430
    2531                                prepare_build()
    2632
    27                                 //Compile using gcc-4.9
    28                                 currentCC = new CC_Desc('gcc-4.9', 'g++-4.9', 'gcc-4.9')
    29                                 cfa_build(bIsFullBuild, architectureFlag)
    30 
    31                                 //Compile latex documentation
    32                                 doc_build()
    33 
    34                                 if( bIsFullBuild ) {
    35                                         //Compile using gcc-5
    36                                         currentCC = new CC_Desc('gcc-5', 'g++-5', 'gcc-5')
    37                                         cfa_build(true, architectureFlag)
    38 
    39                                         //Compile using gcc-4.9
    40                                         currentCC = new CC_Desc('gcc-6', 'g++-6', 'gcc-6')
    41                                         cfa_build(true, architectureFlag)
    42                                 }
     33                                checkout()
     34
     35                                build()
     36
     37                                test()
     38
     39                                benchmark()
     40
     41                                clean()
     42
     43                                build_doc()
     44
     45                                publish()
     46
     47                                notify()
    4348                        }
    4449                }
     
    6267
    6368                //Send email with final results if this is not a full build
    64                 if( !bIsFullBuild && !bIsSandbox ) {
     69                if( !do_sendemail && !bIsSandbox ) {
    6570                        echo 'Notifying users of result'
    6671                        email(currentBuild.result, log_needed)
     
    7580
    7681//===========================================================================================================
    77 // Helper classes/variables/routines to make the status and stage name easier to use
     82// Helper classes/variables/routines
    7883//===========================================================================================================
    7984//Description of a compiler (Must be serializable since pipelines are persistent)
     
    9095}
    9196
    92 //Global Variables defining the compiler and at which point in the build we are
    93 // These variables are used but can't be declared before hand because of wierd scripting rules
    94 // @Field String currentCC
    95 // @Field String status_prefix
    96 
    97 //Wrapper to sync stage name and status name
    98 def build_stage(String name) {
    99         def stage_name = "${currentCC.cc_name} ${name}".trim()
    100         stage stage_name
    101 
    102                 status_prefix = stage_name
    103 }
    104 
    10597//Helper routine to collect information about the git history
    10698def collect_git_info() {
     
    121113
    122114def prepare_build() {
    123         properties ([                                                                   \
    124                 [$class: 'ParametersDefinitionProperty',                                \
    125                         parameterDefinitions: [                                         \
    126                         [$class: 'BooleanParameterDefinition',                          \
    127                                 defaultValue: false,                                    \
    128                                 description: 'If true, the build will be promoted to the do-lang git repository (on successful builds only)', \
    129                                 name: 'isFullBuild'                                     \
    130                         ],                                                              \
    131                         [$class: 'ChoiceParameterDefinition',                           \
    132                                 choices: '64-bit\n32-bit',                                      \
    133                                 defaultValue: '64-bit',                                 \
    134                                 description: 'The architecture to use for compilation', \
    135                                 name: 'buildArchitecture'                                       \
    136                         ]]                                                              \
     115        properties ([                                                                                                   \
     116                [$class: 'ParametersDefinitionProperty',                                                                \
     117                        parameterDefinitions: [                                                                         \
     118                                [$class: 'ChoiceParameterDefinition',                                           \
     119                                        description: 'Which compiler to use',                                   \
     120                                        name: 'param_compiler',                                                         \
     121                                        choices: 'gcc-6\ngcc-5\ngcc-4.9\nclang',                                        \
     122                                        defaultValue: 'gcc-6',                                                          \
     123                                ],                                                                                              \
     124                                [$class: 'ChoiceParameterDefinition',                                           \
     125                                        description: 'The target architecture',                                 \
     126                                        name: 'param_arch',                                                             \
     127                                        choices: '64-bit\n32-bit',                                                      \
     128                                        defaultValue: '64-bit',                                                         \
     129                                ],                                                                                              \
     130                                [$class: 'BooleanParameterDefinition',                                                  \
     131                                        description: 'If false, only the quick test suite is ran',              \
     132                                        name: 'param_allTests',                                                         \
     133                                        defaultValue: false,                                                            \
     134                                ],                                                                                              \
     135                                [$class: 'BooleanParameterDefinition',                                                  \
     136                                        description: 'If true, jenkins also runs benchmarks',           \
     137                                        name: 'param_benchmark',                                                        \
     138                                        defaultValue: false,                                                            \
     139                                ],                                                                                              \
     140                                [$class: 'BooleanParameterDefinition',                                                  \
     141                                        description: 'If true, jenkins also builds documentation',              \
     142                                        name: 'param_doc',                                                              \
     143                                        defaultValue: false,                                                            \
     144                                ],                                                                                              \
     145                                [$class: 'BooleanParameterDefinition',                                                  \
     146                                        description: 'If true, jenkins also publishes results',                 \
     147                                        name: 'param_publish',                                                          \
     148                                        defaultValue: false,                                                            \
     149                                ],                                                                                              \
     150                        ],
    137151                ]])
    138152
    139         bIsFullBuild = isFullBuild == 'true'
    140         architectureFlag = ''
    141         if (buildArchitecture == '64-bit') {
    142                 architectureFlag = '--host=x86_64 CXXFLAGS="-m64" CFAFLAGS="-m64"'
    143         } else if (buildArchitecture == '32-bit'){
    144                 architectureFlag = '--host=i386 CXXFLAGS="-m32" CFAFLAGS="-m32"'
    145         } else {
    146                 architectureFlag = 'ERROR'
    147         }
    148 
    149         echo "FULL BUILD = ${isFullBuild}\nArchitecture = ${buildArchitecture} (flag ${architectureFlag})"
     153        compiler                = compiler_from_params()
     154        architecture    = architecture_from_params()
     155
     156        do_alltests             = param_allTests        .toBoolean()
     157        do_benchmark    = param_benchmark .toBoolean()
     158        do_doc          = param_doc     .toBoolean()
     159        do_publish              = param_publish         .toBoolean()
    150160
    151161        collect_git_info()
    152 
     162}
     163
     164def notify() {
     165        sh 'curl --data "" http://plg2:8082/jenkins/notify'
     166}
     167
     168def make_doc() {
     169        def err = null
     170        try {
     171                sh 'make clean > /dev/null'
     172                sh 'make > /dev/null 2>&1'
     173        }
     174        catch (Exception caughtError) {
     175                err = caughtError //rethrow error later
     176                sh 'cat *.log'
     177        }
     178        finally {
     179                if (err) throw err // Must re-throw exception to propagate error
     180        }
    153181}
    154182
     
    157185//===========================================================================================================
    158186//Compilation script is done here but environnement set-up and error handling is done in main loop
    159 def cfa_build(boolean full_build, String flags) {
    160         build_stage 'Checkout'
    161                 def install_dir = pwd tmp: true
     187def checkout() {
     188        stage 'Checkout'
    162189                //checkout the source code and clean the repo
    163190                checkout scm
     
    168195                //Reset the git repo so no local changes persist
    169196                sh 'git reset --hard'
    170 
    171         build_stage 'Build'
    172 
     197}
     198
     199def build() {
     200        stage 'Build'
     201       
     202                def install_dir = pwd tmp: true
     203               
    173204                //Configure the conpilation (Output is not relevant)
    174205                //Use the current directory as the installation target so nothing
    175206                //escapes the sandbox
    176207                //Also specify the compiler by hand
    177                 sh "./configure CXX=${currentCC.cpp_cc} ${flags} --with-backend-compiler=${currentCC.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
     208                sh "./configure CXX=${compiler.cpp_cc} ${architecture} --with-backend-compiler=${compiler.cfa_backend_cc} --prefix=${install_dir} --enable-silent-rules --quiet"
    178209
    179210                //Compile the project
    180211                sh 'make -j 8 --no-print-directory V=0 install'
    181 
    182         build_stage 'Test'
     212}
     213
     214def test() {
     215        stage 'Test'
    183216
    184217                //Run the tests from the tests directory
    185                 if (full_build) {
     218                if ( do_alltests ) {
    186219                        sh 'make -C src/tests all-tests debug=yes'
    187220                        sh 'make -C src/tests all-tests debug=no'
     
    190223                        sh 'make -C src/tests'
    191224                }
    192 
    193         build_stage 'Benchmark'
     225}
     226
     227def benchmark() {
     228        stage 'Benchmark'
     229
     230                if( !do_bencmark ) return
    194231
    195232                //Write the commit id to Benchmark
     
    198235                //Append bench results
    199236                sh 'make -C src/benchmark --no-print-directory csv-data >> bench.csv'
    200 
    201                 //Then publish the results
    202                 sh 'curl --data @bench.csv http://plg2/~cforall/cgi-bin/publish.cgi'
    203 
    204         build_stage 'Cleanup'
     237}
     238
     239def clean() {
     240        stage 'Cleanup'
    205241
    206242                //do a maintainer-clean to make sure we need to remake from scratch
     
    208244}
    209245
    210 def make_doc() {
    211         def err = null
    212 
    213         try {
    214                 sh 'make clean > /dev/null'
    215                 sh 'make > /dev/null 2>&1'
    216         }
    217 
    218         catch (Exception caughtError) {
    219                 //rethrow error later
    220                 err = caughtError
    221 
    222                 sh 'cat *.log'
    223         }
    224 
    225         finally {
    226                 /* Must re-throw exception to propagate error */
    227                 if (err) {
    228                         throw err
    229                 }
    230         }
    231 }
    232 
    233 def doc_build() {
     246def build_doc() {
    234247        stage 'Documentation'
    235248
    236                 status_prefix = 'Documentation'
     249                if( !do_doc ) return
    237250
    238251                dir ('doc/user') {
     
    243256                        make_doc()
    244257                }
     258}
     259
     260def publish() {
     261        stage 'Publish'
     262
     263                if( !do_publish ) return
     264
     265                //Then publish the results
     266                sh 'curl --data @bench.csv http://plg2:8082/jenkins/publish'
    245267}
    246268
Note: See TracChangeset for help on using the changeset viewer.