forked from Raptor3um/raptoreum
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
100 lines (86 loc) · 3.49 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
// This Jenkinsfile will build a builder image and then run the actual build and tests inside this image
// It's very important to not execute any scripts outside of the builder container, as it's our protection against
// external developers bringing in harmful code into Jenkins.
// Jenkins will only run the build if this Jenkinsfile was not modified in an external pull request. Only branches
// which are part of the Thooneum repo will allow modification to the Jenkinsfile.
def targets = [
'win32',
'win64',
'linux32',
'linux64',
'linux64_nowallet',
'linux64_release',
'mac',
]
def tasks = [:]
for(int i = 0; i < targets.size(); i++) {
def target = targets[i]
tasks["${target}"] = {
node {
def BUILD_NUMBER = sh(returnStdout: true, script: 'echo $BUILD_NUMBER').trim()
def BRANCH_NAME = sh(returnStdout: true, script: 'echo $BRANCH_NAME').trim()
def UID = sh(returnStdout: true, script: 'id -u').trim()
def HOME = sh(returnStdout: true, script: 'echo $HOME').trim()
def pwd = sh(returnStdout: true, script: 'pwd').trim()
checkout scm
def env = [
"BUILD_TARGET=${target}",
"PULL_REQUEST=false",
"JOB_NUMBER=${BUILD_NUMBER}",
]
withEnv(env) {
def builderImageName="thooneum-builder-${target}"
def builderImage
stage("${target}/builder-image") {
builderImage = docker.build("${builderImageName}", "--build-arg BUILD_TARGET=${target} ci -f ci/Dockerfile.builder")
}
builderImage.inside("-t") {
// copy source into fixed path
// we must build under the same path everytime as otherwise caches won't work properly
sh "cp -ra ${pwd}/. /thooneum-src/"
// restore cache
def hasCache = false
try {
copyArtifacts(projectName: "thooneum-thooneum/${BRANCH_NAME}", optional: true, selector: lastSuccessful(), filter: "ci-cache-${target}.tar.gz")
} catch (Exception e) {
}
if (fileExists("ci-cache-${target}.tar.gz")) {
hasCache = true
echo "Using cache from thooneum-thooneum/${BRANCH_NAME}"
} else {
try {
copyArtifacts(projectName: 'thooneum-thooneum/develop', optional: true, selector: lastSuccessful(), filter: "ci-cache-${target}.tar.gz");
} catch (Exception e) {
}
if (fileExists("ci-cache-${target}.tar.gz")) {
hasCache = true
echo "Using cache from thooneum-thooneum/develop"
}
}
if (hasCache) {
sh "cd /thooneum-src && tar xzf ${pwd}/ci-cache-${target}.tar.gz"
} else {
sh "mkdir -p /thooneum-src/ci-cache-${target}"
}
stage("${target}/depends") {
sh 'cd /thooneum-src && ./ci/build_depends.sh'
}
stage("${target}/build") {
sh 'cd /thooneum-src && ./ci/build_src.sh'
}
stage("${target}/test") {
sh 'cd /thooneum-src && ./ci/test_unittests.sh'
}
stage("${target}/test") {
sh 'cd /thooneum-src && ./ci/test_integrationtests.sh'
}
// archive cache and copy it into the jenkins workspace
sh "cd /thooneum-src && tar czfv ci-cache-${target}.tar.gz ci-cache-${target} && cp ci-cache-${target}.tar.gz ${pwd}/"
}
// upload cache
archiveArtifacts artifacts: "ci-cache-${target}.tar.gz", fingerprint: true
}
}
}
}
parallel tasks