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_no, ref) = prepare_build() |
---|
29 | |
---|
30 | node('x64') { |
---|
31 | BuildDir = pwd tmp: true |
---|
32 | SrcDir = pwd tmp: false |
---|
33 | |
---|
34 | 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 | def clean() { |
---|
77 | build_stage('Cleanup', true) { |
---|
78 | // clean the build by wipping the build directory |
---|
79 | dir(BuildDir) { |
---|
80 | deleteDir() |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | |
---|
85 | //Compilation script is done here but environnement set-up and error handling is done in main loop |
---|
86 | // def checkout() { |
---|
87 | // build_stage('Checkout', true) { |
---|
88 | // //checkout the source code and clean the repo |
---|
89 | // final scmVars = checkout scm |
---|
90 | // Settings.GitNewRef = scmVars.GIT_COMMIT |
---|
91 | // Settings.GitOldRef = scmVars.GIT_PREVIOUS_COMMIT |
---|
92 | |
---|
93 | // echo GitLogMessage() |
---|
94 | // } |
---|
95 | // } |
---|
96 | |
---|
97 | //=========================================================================================================== |
---|
98 | // Helper classes/variables/routines |
---|
99 | //=========================================================================================================== |
---|
100 | def prepare_build() { |
---|
101 | // prepare the properties |
---|
102 | properties ([ \ |
---|
103 | buildDiscarder(logRotator( \ |
---|
104 | artifactDaysToKeepStr: '', \ |
---|
105 | artifactNumToKeepStr: '', \ |
---|
106 | daysToKeepStr: '730', \ |
---|
107 | numToKeepStr: '1000' \ |
---|
108 | )), \ |
---|
109 | [$class: 'ParametersDefinitionProperty', \ |
---|
110 | parameterDefinitions: [ \ |
---|
111 | [$class: 'IntergerParameterDefinition', \ |
---|
112 | description: 'The build number to put in the version', \ |
---|
113 | name: 'Build', \ |
---|
114 | ], \ |
---|
115 | ], |
---|
116 | ]]) |
---|
117 | |
---|
118 | // It's unfortunate but it looks like we need to checkout the entire repo just to get |
---|
119 | // - the pretty git printer |
---|
120 | // - Jenkins.tools |
---|
121 | checkout scm |
---|
122 | |
---|
123 | Tools = load "Jenkins/tools.groovy" |
---|
124 | |
---|
125 | currentBuild.description = "Distributing Binaries" |
---|
126 | echo "Distributing build ${params.Build}" |
---|
127 | |
---|
128 | return params.Build |
---|
129 | } |
---|
130 | |
---|