forked from milkytracker/MilkyTracker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
executable file
·194 lines (160 loc) · 6.96 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
def notify(status){
emailext (
body: '$DEFAULT_CONTENT',
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
replyTo: '$DEFAULT_REPLYTO',
subject: '$DEFAULT_SUBJECT',
to: '$DEFAULT_RECIPIENTS'
)
}
@NonCPS
def killall_jobs() {
def jobname = env.JOB_NAME
def buildnum = env.BUILD_NUMBER.toInteger()
def killnums = ""
def job = Jenkins.instance.getItemByFullName(jobname)
def fixed_job_name = env.JOB_NAME.replace('%2F','/')
for (build in job.builds) {
if (!build.isBuilding()) { continue; }
if (buildnum == build.getNumber().toInteger()) { continue; println "equals" }
if (buildnum < build.getNumber().toInteger()) { continue; println "newer" }
echo "Kill task = ${build}"
killnums += "#" + build.getNumber().toInteger() + ", "
build.doStop();
}
if (killnums != "") {
slackSend color: "danger", channel: "#jenkins", message: "Killing task(s) ${fixed_job_name} ${killnums} in favor of #${buildnum}, ignore following failed builds for ${killnums}"
}
echo "Done killing"
}
def buildStep(dockerImage, os, flags, suffix) {
def fixed_job_name = env.JOB_NAME.replace('%2F','/');
def commondir = env.WORKSPACE + '/../' + env.JOB_NAME.replace('%2F','/') + '/';
try {
stage("Building on \"${dockerImage}\" for \"${os}${suffix}\"...") {
properties([pipelineTriggers([githubPush()])])
def dockerImageRef = docker.image("${dockerImage}")
dockerImageRef.pull()
dockerImageRef.inside("-e HOME='/tmp' --privileged --network=host -w /tmp/work") {
checkout scm
if (env.CHANGE_ID) {
echo 'Trying to build pull request'
}
if (!env.CHANGE_ID) {
sh "rm -rf ${env.WORKSPACE}/publishing/deploy/*"
sh "mkdir -p ${env.WORKSPACE}/publishing/deploy/milkytracker"
}
sh "rm -rf build/*"
sh "mkdir -p build/${os}/milkytracker"
sh "mkdir -p lib/"
slackSend color: "good", channel: "#jenkins", message: "Starting ${os} build target..."
try {
sh "platforms/${os}/prep.sh"
} catch(err) {
notify('Prep not found')
}
dir("build/${os}") {
sh "PKG_CONFIG_PATH=/tmp/libs:/opt/${os}/lib/pkgconfig/:/opt/${os}/share/pkgconfig/:/opt/${os}/usr/lib/pkgconfig/:/opt/${os}/usr/share/pkgconfig/ cmake -DCMAKE_BUILD_TYPE=Release ${flags} ../.."
def _NPROCESSORS_ONLN = sh (
script: 'getconf _NPROCESSORS_ONLN',
returnStdout: true
).trim()
sh "VERBOSE=1 cmake --build . --config Release -- -j${_NPROCESSORS_ONLN}"
sh "VERBOSE=1 cmake --build . --config Release --target package -- -j${_NPROCESSORS_ONLN}"
def archive_date = sh (
script: 'date +"-%Y%m%d-%H%M"',
returnStdout: true
).trim()
def release_type = ("${fixed_job_name}-").replace('/','-').replace('MilkyTracker-','').replace('master-','');
if (env.TAG_NAME) {
archive_date = '';
}
dir("milkytracker") {
sh "unzip ../*.zip"
sh "mv -fv ./* ./MilkyTracker"
sh "cp ../../../resources/packaging/amigaos/milkytracker_dir.info ./MilkyTracker.info"
sh "lha -c ../milkytracker-${release_type}${os}${suffix}${archive_date}.lha *"
}
if (!env.CHANGE_ID) {
def release_type_tag = 'develop';
def pre_release = '--pre-release';
if (env.TAG_NAME) {
pre_release = '';
release_type_tag = env.TAG_NAME;
} else if (env.BRANCH_NAME.equals('master')) {
release_type_tag = 'nightly';
}
try {
sh "github-release release --user amigaports --repo milkytracker --tag ${release_type_tag} --name \"milkytracker ${release_type_tag}\" --description \"${release_type_tag} releases\" ${pre_release}"
} catch(err) {
}
sh "github-release upload --user amigaports --repo milkytracker --tag ${release_type_tag} --name \"milkytracker-${release_type}${os}${suffix}${archive_date}.lha\" --file milkytracker-${release_type}${os}${suffix}${archive_date}.lha --replace"
}
archiveArtifacts artifacts: "**.lha"
stash includes: "**.lha", name: "${os}"
}
if (!env.CHANGE_ID) {
sh "mkdir -p ${env.WORKSPACE}/publishing/deploy/milkytracker/${os}/"
sh "echo '${env.BUILD_NUMBER}|${env.BUILD_URL}' > ${env.WORKSPACE}/publishing/deploy/milkytracker/${os}/BUILD"
sh "cp -fvr build/${os}/src/tracker/milkytracker ${env.WORKSPACE}/publishing/deploy/milkytracker/${os}/"
}
slackSend color: "good", channel: "#jenkins", message: "Build ${fixed_job_name} #${env.BUILD_NUMBER} Target: ${os} DockerImage: ${dockerImage} successful!"
}
}
} catch(err) {
slackSend color: "danger", channel: "#jenkins", message: "Build Failed: ${fixed_job_name} #${env.BUILD_NUMBER} Target: ${os} DockerImage: ${dockerImage} (<${env.BUILD_URL}|Open>)"
currentBuild.result = 'FAILURE'
notify("Build Failed: ${fixed_job_name} #${env.BUILD_NUMBER} Target: ${os} DockerImage: ${dockerImage}");
throw err;
}
}
node('master') {
killall_jobs();
def fixed_job_name = env.JOB_NAME.replace('%2F','/');
slackSend color: "good", channel: "#jenkins", message: "Build Started: ${fixed_job_name} #${env.BUILD_NUMBER} (<${env.BUILD_URL}|Open>)";
checkout scm;
def branches = [:]
def project = readJSON file: "JenkinsEnv.json";
project.builds.each { v ->
branches["Build ${v.DockerTag}${v.ReleaseSuffix}"] = {
node {
buildStep("${v.DockerRoot}/${v.DockerImage}:${v.DockerTag}", "${v.DockerTag}", "${v.BuildParam}", "${v.ReleaseSuffix}");
}
}
}
sh "rm -rf ./*"
parallel branches;
stage("Publishing") {
sh "rm -rfv publishing/"
project.builds.each { v ->
try {
// ${os}
unstash("${v.DockerTag}");
} catch(err) {
notify("Stash ${v.DockerTag} not found");
}
}
sh "mkdir -p ./publishing/deploy/milkytracker"
sh "mv -fv ./*.lha ./publishing/deploy/milkytracker"
if (env.TAG_NAME) {
sh "echo $TAG_NAME > ./publishing/deploy/STABLE"
sh "ssh $DEPLOYHOST mkdir -p public_html/downloads/releases/milkytracker/$TAG_NAME"
sh "scp -r ./publishing/deploy/milkytracker/* $DEPLOYHOST:~/public_html/downloads/releases/milkytracker/$TAG_NAME/"
sh "scp ./publishing/deploy/STABLE $DEPLOYHOST:~/public_html/downloads/releases/milkytracker/"
} else if (env.BRANCH_NAME.equals('master')) {
def deploy_url = sh (
script: 'echo "nightly/milkytracker/`date +\'%Y\'`/`date +\'%m\'`/`date +\'%d\'`/"',
returnStdout: true
).trim()
sh "date +'%Y-%m-%d %H:%M:%S' > publishing/deploy/BUILDTIME"
sh "ssh $DEPLOYHOST mkdir -p public_html/downloads/nightly/milkytracker/`date +'%Y'`/`date +'%m'`/`date +'%d'`/"
sh "scp -r ./publishing/deploy/milkytracker/* $DEPLOYHOST:~/public_html/downloads/nightly/milkytracker/`date +'%Y'`/`date +'%m'`/`date +'%d'`/"
sh "scp ./publishing/deploy/BUILDTIME $DEPLOYHOST:~/public_html/downloads/nightly/milkytracker/"
slackSend color: "good", channel: "#jenkins", message: "New ${fixed_job_name} build #${env.BUILD_NUMBER} to web (<https://dl.amigadev.com/${deploy_url}|https://dl.amigadev.com/${deploy_url}>)"
}
}
}