forked from RPi-Distro/pi-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
177 lines (176 loc) · 7.45 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
#!groovy
pipeline {
agent {
label "docker"
}
options {
timestamps()
timeout(time: 3, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '5'))
disableConcurrentBuilds()
}
environment {
// In case another branch beside master or develop should be deployed, enter it here
BRANCH_TO_DEPLOY = 'xyz'
GITHUB_TOKEN = credentials('cdc81429-53c7-4521-81e9-83a7992bca76')
DISCORD_WEBHOOK = credentials('991ce248-5da9-4068-9aea-8a6c2c388a19')
CURRENT_DATE = sh(
script: "printf \$(date +%Y-%m-%d)",
returnStdout: true
)
}
parameters {
string(name: 'ALIAS_RELEASE', defaultValue: '', description: 'Which release of Aliaswallet should be used? (i. e. 4.3.0 or Build123)')
string(name: 'GIT_COMMIT_SHORT', defaultValue: '', description: 'Git short commit, which is part of the name of required archive.')
}
stages {
stage('Notification') {
steps {
// Using result state 'ABORTED' to mark the message on discord with a white border.
// Makes it easier to distinguish job-start from job-finished
discordSend(
description: "Started build #$env.BUILD_NUMBER",
image: '',
link: "$env.BUILD_URL",
successful: true,
result: "ABORTED",
thumbnail: 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png',
title: "$env.JOB_NAME",
webhookURL: "${DISCORD_WEBHOOK}"
)
}
}
stage('Check if required parameters given') {
when {
allOf {
expression { ALIAS_RELEASE == "" }
expression { GIT_COMMIT_SHORT == "" }
}
}
steps {
script {
// Abort build if required params are empty
currentBuild.result = 'ABORTED'
error('ALIAS_RELEASE and GIT_COMMIT_SHORT must be given!')
}
}
}
stage('Build image') {
steps {
script {
sh(
script: """
sudo modprobe loop max_loop=256
rm -rf ${WORKSPACE}/work
echo IMG_NAME=Aliaswallet > config
echo ALIAS_RELEASE=${ALIAS_RELEASE} >> config
echo GIT_COMMIT_SHORT=${GIT_COMMIT_SHORT} >> config
echo ENABLE_SSH=1 >> config
cat config
touch ./stage4/SKIP ./stage4/SKIP_IMAGES ./stage5/SKIP ./stage5/SKIP_IMAGES
./build-docker.sh
"""
)
}
}
}
stage('Deploy image') {
steps {
script {
sh(
script: """
docker run \\
--rm \\
-t \\
-e GITHUB_TOKEN=${GITHUB_TOKEN} \\
-v ${WORKSPACE}/deploy/:/filesToUpload \\
aliascash/github-uploader:latest \\
github-release upload \\
--user aliascash \\
--repo alias-wallet \\
--tag ${ALIAS_RELEASE} \\
--name "Alias-${ALIAS_RELEASE}-${GIT_COMMIT_SHORT}-RaspbianLight.zip" \\
--file /filesToUpload/image_${CURRENT_DATE}-Aliaswallet-lite.zip \\
--replace
"""
)
}
}
}
}
post {
always {
sh "docker system prune --all --force"
}
success {
script {
if (!hudson.model.Result.SUCCESS.equals(currentBuild.getPreviousBuild()?.getResult())) {
emailext(
subject: "GREEN: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: '${JELLY_SCRIPT,template="html"}',
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
// to: "to@be.defined",
// replyTo: "to@be.defined"
)
}
discordSend(
description: "Build #$env.BUILD_NUMBER finished successfully",
image: '',
link: "$env.BUILD_URL",
successful: true,
thumbnail: 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png',
title: "$env.JOB_NAME",
webhookURL: "${DISCORD_WEBHOOK}"
)
}
}
unstable {
emailext(
subject: "YELLOW: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: '${JELLY_SCRIPT,template="html"}',
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
// to: "to@be.defined",
// replyTo: "to@be.defined"
)
discordSend(
description: "Build #$env.BUILD_NUMBER finished unstable",
image: '',
link: "$env.BUILD_URL",
successful: true,
result: "UNSTABLE",
thumbnail: 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png',
title: "$env.JOB_NAME",
webhookURL: "${DISCORD_WEBHOOK}"
)
}
failure {
emailext(
subject: "RED: '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: '${JELLY_SCRIPT,template="html"}',
recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']],
// to: "to@be.defined",
// replyTo: "to@be.defined"
)
discordSend(
description: "Build #$env.BUILD_NUMBER failed!",
image: '',
link: "$env.BUILD_URL",
successful: false,
thumbnail: 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png',
title: "$env.JOB_NAME",
webhookURL: "${DISCORD_WEBHOOK}"
)
}
aborted {
discordSend(
description: "Build #$env.BUILD_NUMBER aborted!",
image: '',
link: "$env.BUILD_URL",
successful: false,
thumbnail: 'https://wiki.jenkins-ci.org/download/attachments/2916393/headshot.png',
title: "$env.JOB_NAME",
webhookURL: "${DISCORD_WEBHOOK}"
)
}
}
}