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 | final commit, build
|
---|
29 | (commit, build) = prepare_build()
|
---|
30 |
|
---|
31 | node('x64') {
|
---|
32 | BuildDir = pwd tmp: true
|
---|
33 | SrcDir = pwd tmp: false
|
---|
34 |
|
---|
35 | Tools.Clean()
|
---|
36 |
|
---|
37 | Tools.Checkout( commit )
|
---|
38 |
|
---|
39 | final version = GetVersion( build )
|
---|
40 | }
|
---|
41 |
|
---|
42 | // Update the build directories when exiting the node
|
---|
43 | BuildDir = pwd tmp: true
|
---|
44 | SrcDir = pwd tmp: false
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | //If an exception is caught we need to change the status and remember to
|
---|
49 | //attach the build log to the email
|
---|
50 | // catch (Exception caughtError) {
|
---|
51 | // //rethrow error later
|
---|
52 | // err = caughtError
|
---|
53 |
|
---|
54 | // echo err.toString()
|
---|
55 |
|
---|
56 | // //An error has occured, the build log is relevent
|
---|
57 | // log_needed = true
|
---|
58 |
|
---|
59 | // //Store the result of the build log
|
---|
60 | // currentBuild.result = "${StageName} FAILURE".trim()
|
---|
61 | // }
|
---|
62 |
|
---|
63 | finally {
|
---|
64 | // //Send email with final results if this is not a full build
|
---|
65 | // email(log_needed)
|
---|
66 |
|
---|
67 | // echo 'Distribution Completed'
|
---|
68 |
|
---|
69 | // /* Must re-throw exception to propagate error */
|
---|
70 | // if (err) {
|
---|
71 | // throw err
|
---|
72 | // }
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | //===========================================================================================================
|
---|
77 | // Main compilation routines
|
---|
78 | //===========================================================================================================
|
---|
79 | def GetVersion(build) {
|
---|
80 | final pver = sh(
|
---|
81 | returnStdout: true,
|
---|
82 | script: "sed 's/AC_INIT(\\[cfa-cc\\],\\[\\(.*\\)\\],\\[cforall@plg.uwaterloo.ca\\])/\\1/;t;d' ${SrcDir}/configure.ac"
|
---|
83 | ).trim()
|
---|
84 |
|
---|
85 | final version = "${pver}.${build}"
|
---|
86 |
|
---|
87 | echo "Package Version: ${pver}"
|
---|
88 | echo "Build Version: ${build}"
|
---|
89 | echo "Long Version: ${version}"
|
---|
90 |
|
---|
91 | return version
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | //===========================================================================================================
|
---|
96 | // Helper classes/variables/routines
|
---|
97 | //===========================================================================================================
|
---|
98 | def prepare_build() {
|
---|
99 | // prepare the properties
|
---|
100 | properties ([ \
|
---|
101 | buildDiscarder(logRotator( \
|
---|
102 | artifactDaysToKeepStr: '', \
|
---|
103 | artifactNumToKeepStr: '', \
|
---|
104 | daysToKeepStr: '730', \
|
---|
105 | numToKeepStr: '1000' \
|
---|
106 | )), \
|
---|
107 | [$class: 'ParametersDefinitionProperty', \
|
---|
108 | parameterDefinitions: [ \
|
---|
109 | [$class: 'StringParameterDefinition', \
|
---|
110 | description: 'The git commit to checkout', \
|
---|
111 | name: 'GitRef', \
|
---|
112 | defaultValue: '', \
|
---|
113 | ], \
|
---|
114 | [$class: 'StringParameterDefinition', \
|
---|
115 | description: 'Build Number to put into the version', \
|
---|
116 | name: 'Build', \
|
---|
117 | defaultValue: '0', \
|
---|
118 | ], \
|
---|
119 | ],
|
---|
120 | ]])
|
---|
121 |
|
---|
122 | // It's unfortunate but it looks like we need to checkout the entire repo just to get
|
---|
123 | // - the pretty git printer
|
---|
124 | // - Jenkins.tools
|
---|
125 | checkout scm
|
---|
126 |
|
---|
127 | Tools = load "Jenkins/tools.groovy"
|
---|
128 |
|
---|
129 | currentBuild.description = "Distributing Tarball"
|
---|
130 | def ref = params.GitRef ? params.GitRef : "HEAD"
|
---|
131 | echo "Distributing git commit ${ref}"
|
---|
132 |
|
---|
133 | return [params.GitRef, params.Build]
|
---|
134 | }
|
---|
135 |
|
---|