-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathJenkinsfile
174 lines (153 loc) · 6.06 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!groovy
//
// This DEMO shows how to write a cross-platform(Windows/Android/Linux/iOS/MacOSX) build.
// Pipeline:
// 1.Source code checkout -> 2.Cross-Platform Build -> 3.Archiving each platform's binaries -> 4.Cleanup
//
// We assume the project's structure is like this:
//
// --project_root
// --build
// -- android-build.sh (Script to build for Android platform, will output binaries into 'dist/android/armeabi-v7a')
// -- iphoneos-build.sh (Script to build for iOS, will output binaries into 'dist/ios')
// -- macos-build.sh (Script to build for MacOSX, will output binaries into 'dist/macos')
// --src
// -- CMakeLists.txt
// -- (Your source files structured by CMake or anyother)
// --dist
// -- (Directory to hold each platform distribution binaries.)
// -- android
// -- win32
// -- ios
// -- macos
// --symbols
// -- win32 (Dir to hold PDB symbols generate from CMake)
//
node('master') {
//
// #1
// Fresh checkout your cross-platform project onto the master node.
// NOTE To avoid checkout on each platform again and again, we just checkout once on the master node,
// then stash/unstash onto the target platform.
//
stage('Checkout') {
timeout(time: 10, unit: 'SECONDS') {
// Checkout source code onto master node.
// You can generate the 'checkout' command by using "Project->Pipeline Syntax->Snippet Generator"
checkout(GENERATE BY YOURSELF)
// Stash all source files for another platform usage.
// NOTE: the stashed file's scope is in node 'master', so we can unstash it later.
stash name: 'YOUR_CROSSPLATFORM_SOURCES'
}
}
//
// #2
// Build on each platform.
//
stage('Build Cross-Platform Libraries') {
timeout(5) {
parallel (
"win32-stream" : {
node('win32') {
// This will copy all files packaged in YOUR_CROSSPLATFORM_SOURCES to agent workspace root directory.
// To copy to another agent directory, see [https://github.com/BillHoo/pipeline-examples/tree/master/pipeline-examples/unstash-different-dir]
unstash 'YOUR_CROSSPLATFORM_SOURCES'
// Change current directory to "build", and run CMake.
// NOTE we assume your CMake INSTALL target will put output binaries into 'dist/win32' for later usage.
dir('build') {
bat 'cmake ..\\src'
bat 'cmake --build . --config RelWithDebInfo --target INSTALL'
}
}
},
"android-stream" : {
node('android') {
unstash 'YOUR_CROSSPLATFORM_SOURCES'
// Change current directory to "build", and run Android build script.
dir('build') {
sh './android-build.sh'
}
}
},
"ios-stream" : {
node('ios') {
unstash 'YOUR_CROSSPLATFORM_SOURCES'
// Change current directory to "build", and run iOS build script.
dir('build') {
sh './iphoneos-build.sh'
}
}
},
"mac-stream" : {
node('mac') {
unstash 'YOUR_CROSSPLATFORM_SOURCES'
// Change current directory to "build", and run MacOSX build script.
dir('build') {
sh './macos-build.sh'
}
}
}
) // parallel
} // Timeout
} // State cross-platform build
//
// #3
// Cross-Platform Libraries Distribution
//
stage('Libraries Distribution') {
parallel(
"win32-archiving" : {
node('win32') {
step([$class: 'ArtifactArchiver', artifacts: 'dist\\win32\\*', fingerprint: true])
step([$class: 'ArtifactArchiver', artifacts: 'symbols\\win32\\*', fingerprint: true])
}
},
"android-archiving" : {
node('android') {
step([$class: 'ArtifactArchiver', artifacts: 'dist/android/armeabi-v7a/*', fingerprint: true])
}
},
"ios-archiving" : {
node('ios') {
step([$class: 'ArtifactArchiver', artifacts: 'dist/ios/*', fingerprint: true])
}
},
"mac-archiving" : {
node('mac') {
step([$class: 'ArtifactArchiver', artifacts: 'dist/macos/*', fingerprint: true])
}
}
) // parallel
}
//
// #4
// Final cleanup
// Why we need this cleaup?
// stash/unstash command just copy files from source to dest without any version control stuff like Git/SVN did.
// So all files will stay in agent workspace if we dont't remove it, and may cause issues when we launch next build.
//
stage('Cleanup') {
parallel(
"win32-clean" : {
node('win32') {
deleteDir()
}
},
"android-clean" : {
node('android') {
deleteDir()
}
},
"ios-clean" : {
node('ios') {
deleteDir()
}
},
"mac-clean" : {
node('mac') {
deleteDir()
}
}
) // parallel
} // Cleanup
} // node master