| [4011b98] | 1 | #!groovy
 | 
|---|
 | 2 | 
 | 
|---|
 | 3 | import groovy.transform.Field
 | 
|---|
 | 4 | 
 | 
|---|
 | 5 | // For skipping stages
 | 
|---|
 | 6 | import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | //===========================================================================================================
 | 
|---|
 | 9 | // Main loop of the compilation
 | 
|---|
 | 10 | //===========================================================================================================
 | 
|---|
 | 11 | 
 | 
|---|
 | 12 | node('master') {
 | 
|---|
 | 13 |         // Globals
 | 
|---|
 | 14 |         BuildDir  = pwd tmp: true
 | 
|---|
 | 15 |         SrcDir    = pwd tmp: false
 | 
|---|
 | 16 |         Settings  = null
 | 
|---|
 | 17 |         Tools = load "Jenkins/tools.groovy"
 | 
|---|
 | 18 | 
 | 
|---|
 | 19 |         // Local variables
 | 
|---|
 | 20 |         def err = null
 | 
|---|
 | 21 |         def log_needed = false
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 |         currentBuild.result = "SUCCESS"
 | 
|---|
 | 24 | 
 | 
|---|
 | 25 |         try {
 | 
|---|
 | 26 |                 //Wrap build to add timestamp to command line
 | 
|---|
 | 27 |                 wrap([$class: 'TimestamperBuildWrapper']) {
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 |                         (build_no, ref) = prepare_build()
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 |                         node('x64') {
 | 
|---|
 | 32 |                                 BuildDir  = pwd tmp: true
 | 
|---|
 | 33 |                                 SrcDir    = pwd tmp: false
 | 
|---|
 | 34 | 
 | 
|---|
 | 35 |                                 clean()
 | 
|---|
 | 36 | 
 | 
|---|
 | 37 |                                 // checkout()
 | 
|---|
 | 38 |                         }
 | 
|---|
 | 39 | 
 | 
|---|
 | 40 |                         // Update the build directories when exiting the node
 | 
|---|
 | 41 |                         BuildDir  = pwd tmp: true
 | 
|---|
 | 42 |                         SrcDir    = pwd tmp: false
 | 
|---|
 | 43 |                 }
 | 
|---|
 | 44 |         }
 | 
|---|
 | 45 | 
 | 
|---|
 | 46 |         //If an exception is caught we need to change the status and remember to
 | 
|---|
 | 47 |         //attach the build log to the email
 | 
|---|
 | 48 |         catch (Exception caughtError) {
 | 
|---|
 | 49 |                 // //rethrow error later
 | 
|---|
 | 50 |                 // err = caughtError
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 |                 // echo err.toString()
 | 
|---|
 | 53 | 
 | 
|---|
 | 54 |                 // //An error has occured, the build log is relevent
 | 
|---|
 | 55 |                 // log_needed = true
 | 
|---|
 | 56 | 
 | 
|---|
 | 57 |                 // //Store the result of the build log
 | 
|---|
 | 58 |                 // currentBuild.result = "${StageName} FAILURE".trim()
 | 
|---|
 | 59 |         }
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |         finally {
 | 
|---|
 | 62 |                 // //Send email with final results if this is not a full build
 | 
|---|
 | 63 |                 // email(log_needed)
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |                 // echo 'Distribution Completed'
 | 
|---|
 | 66 | 
 | 
|---|
 | 67 |                 // /* Must re-throw exception to propagate error */
 | 
|---|
 | 68 |                 // if (err) {
 | 
|---|
 | 69 |                 //      throw err
 | 
|---|
 | 70 |                 // }
 | 
|---|
 | 71 |         }
 | 
|---|
 | 72 | }
 | 
|---|
 | 73 | 
 | 
|---|
 | 74 | //===========================================================================================================
 | 
|---|
 | 75 | // Main compilation routines
 | 
|---|
 | 76 | //===========================================================================================================
 | 
|---|
 | 77 | def clean() {
 | 
|---|
 | 78 |         build_stage('Cleanup', true) {
 | 
|---|
 | 79 |                 // clean the build by wipping the build directory
 | 
|---|
 | 80 |                 dir(BuildDir) {
 | 
|---|
 | 81 |                         deleteDir()
 | 
|---|
 | 82 |                 }
 | 
|---|
 | 83 |         }
 | 
|---|
 | 84 | }
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 | //Compilation script is done here but environnement set-up and error handling is done in main loop
 | 
|---|
 | 87 | // def checkout() {
 | 
|---|
 | 88 | //      build_stage('Checkout', true) {
 | 
|---|
 | 89 | //              //checkout the source code and clean the repo
 | 
|---|
 | 90 | //              final scmVars = checkout scm
 | 
|---|
 | 91 | //              Settings.GitNewRef = scmVars.GIT_COMMIT
 | 
|---|
 | 92 | //              Settings.GitOldRef = scmVars.GIT_PREVIOUS_COMMIT
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | //              echo GitLogMessage()
 | 
|---|
 | 95 | //      }
 | 
|---|
 | 96 | // }
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 | //===========================================================================================================
 | 
|---|
 | 99 | // Helper classes/variables/routines
 | 
|---|
 | 100 | //===========================================================================================================
 | 
|---|
 | 101 | def prepare_build() {
 | 
|---|
 | 102 |         // prepare the properties
 | 
|---|
 | 103 |         properties ([                                                                                                   \
 | 
|---|
 | 104 |                 buildDiscarder(logRotator(                                                                              \
 | 
|---|
 | 105 |                         artifactDaysToKeepStr: '',                                                                      \
 | 
|---|
 | 106 |                         artifactNumToKeepStr: '',                                                                       \
 | 
|---|
 | 107 |                         daysToKeepStr: '730',                                                                           \
 | 
|---|
 | 108 |                         numToKeepStr: '1000'                                                                            \
 | 
|---|
 | 109 |                 )),                                                                                                             \
 | 
|---|
 | 110 |                 [$class: 'ParametersDefinitionProperty',                                                                \
 | 
|---|
 | 111 |                         parameterDefinitions: [                                                                         \
 | 
|---|
 | 112 |                                 [$class: 'IntergerParameterDefinition',                                         \
 | 
|---|
 | 113 |                                         description: 'The build number to put in the version',          \
 | 
|---|
 | 114 |                                         name: 'Build',                                                                  \
 | 
|---|
 | 115 |                                 ],                                                                                              \
 | 
|---|
 | 116 |                         ],
 | 
|---|
 | 117 |                 ]])
 | 
|---|
 | 118 | 
 | 
|---|
 | 119 |         currentBuild.description = "Distributing Binaries"
 | 
|---|
 | 120 |         echo "Distributing build ${params.Build}"
 | 
|---|
 | 121 | 
 | 
|---|
 | 122 |         return params.Build
 | 
|---|
| [6855d14] | 123 | }
 | 
|---|
| [4011b98] | 124 | 
 | 
|---|