| 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 |
|
|---|
| 18 | // Local variables
|
|---|
| 19 | def err = null
|
|---|
| 20 | def log_needed = false
|
|---|
| 21 |
|
|---|
| 22 | currentBuild.result = "SUCCESS"
|
|---|
| 23 |
|
|---|
| 24 | try {
|
|---|
| 25 | //Wrap build to add timestamp to command line
|
|---|
| 26 | wrap([$class: 'TimestamperBuildWrapper']) {
|
|---|
| 27 |
|
|---|
| 28 | build_id = prepare_build()
|
|---|
| 29 |
|
|---|
| 30 | node('x64') {
|
|---|
| 31 | BuildDir = pwd tmp: true
|
|---|
| 32 | SrcDir = pwd tmp: false
|
|---|
| 33 |
|
|---|
| 34 | Tools.clean()
|
|---|
| 35 |
|
|---|
| 36 | // checkout()
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | // Update the build directories when exiting the node
|
|---|
| 40 | BuildDir = pwd tmp: true
|
|---|
| 41 | SrcDir = pwd tmp: false
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | //If an exception is caught we need to change the status and remember to
|
|---|
| 46 | //attach the build log to the email
|
|---|
| 47 | catch (Exception caughtError) {
|
|---|
| 48 | // //rethrow error later
|
|---|
| 49 | // err = caughtError
|
|---|
| 50 |
|
|---|
| 51 | // echo err.toString()
|
|---|
| 52 |
|
|---|
| 53 | // //An error has occured, the build log is relevent
|
|---|
| 54 | // log_needed = true
|
|---|
| 55 |
|
|---|
| 56 | // //Store the result of the build log
|
|---|
| 57 | // currentBuild.result = "${StageName} FAILURE".trim()
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | finally {
|
|---|
| 61 | // //Send email with final results if this is not a full build
|
|---|
| 62 | // email(log_needed)
|
|---|
| 63 |
|
|---|
| 64 | // echo 'Distribution Completed'
|
|---|
| 65 |
|
|---|
| 66 | // /* Must re-throw exception to propagate error */
|
|---|
| 67 | // if (err) {
|
|---|
| 68 | // throw err
|
|---|
| 69 | // }
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | //===========================================================================================================
|
|---|
| 74 | // Main compilation routines
|
|---|
| 75 | //===========================================================================================================
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | //Compilation script is done here but environnement set-up and error handling is done in main loop
|
|---|
| 79 | // def checkout() {
|
|---|
| 80 | // build_stage('Checkout', true) {
|
|---|
| 81 | // //checkout the source code and clean the repo
|
|---|
| 82 | // final scmVars = checkout scm
|
|---|
| 83 | // Settings.GitNewRef = scmVars.GIT_COMMIT
|
|---|
| 84 | // Settings.GitOldRef = scmVars.GIT_PREVIOUS_COMMIT
|
|---|
| 85 |
|
|---|
| 86 | // echo GitLogMessage()
|
|---|
| 87 | // }
|
|---|
| 88 | // }
|
|---|
| 89 |
|
|---|
| 90 | //===========================================================================================================
|
|---|
| 91 | // Helper classes/variables/routines
|
|---|
| 92 | //===========================================================================================================
|
|---|
| 93 | def prepare_build() {
|
|---|
| 94 | // prepare the properties
|
|---|
| 95 | properties ([ \
|
|---|
| 96 | buildDiscarder(logRotator( \
|
|---|
| 97 | artifactDaysToKeepStr: '', \
|
|---|
| 98 | artifactNumToKeepStr: '', \
|
|---|
| 99 | daysToKeepStr: '730', \
|
|---|
| 100 | numToKeepStr: '1000' \
|
|---|
| 101 | )), \
|
|---|
| 102 | [$class: 'ParametersDefinitionProperty', \
|
|---|
| 103 | parameterDefinitions: [ \
|
|---|
| 104 | [$class: 'StringParameterDefinition', \
|
|---|
| 105 | description: 'The build to put in the version', \
|
|---|
| 106 | name: 'Build', \
|
|---|
| 107 | defaultValue: '', \
|
|---|
| 108 | ], \
|
|---|
| 109 | ],
|
|---|
| 110 | ]])
|
|---|
| 111 |
|
|---|
| 112 | // It's unfortunate but it looks like we need to checkout the entire repo just to get
|
|---|
| 113 | // - the pretty git printer
|
|---|
| 114 | // - Jenkins.tools
|
|---|
| 115 | checkout scm
|
|---|
| 116 |
|
|---|
| 117 | Tools = load "Jenkins/tools.groovy"
|
|---|
| 118 |
|
|---|
| 119 | currentBuild.description = "Distributing Binaries"
|
|---|
| 120 |
|
|---|
| 121 | if (!params.Build) {
|
|---|
| 122 | params.Build = Jenkins.instance.getItem('Cforall Full Build').lastSuccessfulBuild.number
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | echo "Distributing build ${params.Build}"
|
|---|
| 126 |
|
|---|
| 127 | return params.Build
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|