-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
113 lines (104 loc) · 4.66 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
Map config = [
defaultTargets: '6x 7x 8x',
defaultImageUrls: "",
defaultWbdevImage: '',
defaultEnableTelegramAlert: false,
customReleaseBranchPattern: '^\b$' // never-matching pattern
]
pipeline {
agent {
label 'devenv'
}
parameters {
string(name: 'TARGETS', defaultValue: config.defaultTargets, description: 'space-separated list')
string(name: 'FIT_URLS', defaultValue: config.defaultImageUrls, description: 'space-separated list')
booleanParam(name: 'ADD_VERSION_SUFFIX', defaultValue: true, description: 'for non dev/* branches')
booleanParam(name: 'UPLOAD_TO_POOL', defaultValue: true,
description: 'works only with ADD_VERSION_SUFFIX to keep staging clean')
booleanParam(name: 'CLEAN', defaultValue: false, description: 'force cleaned on dev/* branches')
booleanParam(name: 'FORCE_OVERWRITE', defaultValue: false, description: 'replace existing version of package in apt')
booleanParam(name: 'REPLACE_RELEASE', defaultValue: false, description: 'replace existing github release')
string(name: 'WBDEV_IMAGE', defaultValue: config.defaultWbdevImage, description: 'docker image path and tag')
booleanParam(name: 'ENABLE_TELEGRAM_ALERT', defaultValue: config.defaultEnableTelegramAlert, description: 'send alert if build fails')
}
environment {
RESULT_SUBDIR = 'pkgs'
// Initialize params as envvars, workaround for bug https://issues.jenkins-ci.org/browse/JENKINS-41929
WBDEV_IMAGE = "${params.WBDEV_IMAGE}"
}
stages {
stage('Cleanup workspace') {
steps {
cleanWs deleteDirs: true, patterns: [[pattern: "$RESULT_SUBDIR", type: 'INCLUDE']]
}
}
stage('Determine version suffix') {
when { expression {
params.ADD_VERSION_SUFFIX && !wb.isBranchRelease(env.BRANCH_NAME, config.customReleaseBranchPattern)
}}
steps {
script {
def baseCommit = sh(returnStdout: true, script: '''\\
git log --diff-filter=A --cherry --pretty=format:"%h" -- debian/changelog''').trim()
def versionSuffix = sh(returnStdout: true, script: """\\
echo ~exp~`echo ${BRANCH_NAME} | sed -e 's/\\W/+/g' -e 's/_/+/g'`~`\\
git rev-list --count HEAD...${baseCommit}`~g`\\
git rev-parse --short HEAD`""").trim()
env.VERSION_SUFFIX = versionSuffix
}
}
}
stage('Setup builds') {
steps {
script {
def targets = params.TARGETS.split(' ')
def imageUrls = params.FIT_URLS.split(' ')
targets.eachWithIndex { target, i ->
def currentUrl = ''
if (i < imageUrls.size()) {
currentUrl = imageUrls[i]
}
def currentTarget = target
def versionSuffix = env.VERSION_SUFFIX?:''
stage("Build ${currentTarget}") {
sh "wbdev root bash -c 'VERSION_SUFFIX=${versionSuffix} ./make_deb.sh ${currentTarget} ${currentUrl}'"
}
}
}
}
post {
always {
sh "mkdir -p $RESULT_SUBDIR && mv *.deb $RESULT_SUBDIR/ && wbdev root chown -R jenkins:jenkins $RESULT_SUBDIR"
}
success {
archiveArtifacts artifacts: "$RESULT_SUBDIR/*.deb"
}
}
}
stage('Setup deploy') {
when { expression {
params.UPLOAD_TO_POOL && params.ADD_VERSION_SUFFIX
}}
steps {
wbDeploy projectSubdir: '.',
resultSubdir: env.RESULT_SUBDIR,
forceOverwrite: params.FORCE_OVERWRITE,
replaceRelease: params.REPLACE_RELEASE,
uploadJob: wb.repos.devTools.uploadJob,
aptlyConfig: wb.repos.devTools.aptlyConfig
}
}
}
post {
always { script {
if (params.ENABLE_TELEGRAM_ALERT || wb.isBranchRelease(env.BRANCH_NAME, config.customReleaseBranchPattern)) {
wb.notifyMaybeBuildRestored()
}
}}
failure { script {
if (params.ENABLE_TELEGRAM_ALERT || wb.isBranchRelease(env.BRANCH_NAME, config.customReleaseBranchPattern)) {
wb.notifyBuildFailed()
}
}}
}
}