forked from lbthomsen/subutai-ovs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJenkinsfile
116 lines (99 loc) · 3.17 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
#!groovy
notifyBuildDetails = ""
agentCommitId = ""
try {
notifyBuild('STARTED')
node("deb") {
deleteDir()
stage("Checkout source")
notifyBuildDetails = "\nFailed on Stage - Checkout source"
String date = new Date().format( 'yyyyMMddHHMMSS' )
def CWD = pwd()
def release = env.BRANCH_NAME
sh """
#set +x
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
rm -rf *
cd ${CWD} || exit 1
# Clone ovs-deb code
git clone https://github.com/subutai-io/ovs-deb
cd ovs-deb
git checkout ${release}
"""
stage("Tweaks for version")
notifyBuildDetails = "\nFailed on Stage - Version tweaks"
sh """
cd ${CWD}/ovs-deb || exit 1
export ovs_version=\$(git describe --abbrev=0 --tags)+\$(date +%Y%m%d%H%M%S0)
echo "VERSION is \$ovs_version"
cd ${CWD}/ovs-deb && sed -i 's/quilt/native/' debian/source/format
dch -v "\$ovs_version" -D stable "Test build for \$ovs_version" 1>/dev/null 2>/dev/null
"""
stage("Build subutai-ovs package")
notifyBuildDetails = "\nFailed on Stage - Build package"
sh """
cd ${CWD}/ovs-deb
dpkg-buildpackage -rfakeroot -us -uc
cd ${CWD} || exit 1
for i in *.deb; do
echo '\$i:';
dpkg -c \$i;
done
"""
stage("Upload Packages")
notifyBuildDetails = "\nFailed on Stage - Upload"
sh """
cd ${CWD}
touch uploading_ovs
scp uploading_ovs subutai*.deb [email protected]:incoming/${release}/
ssh [email protected] sh /var/reprepro/scripts/scan-incoming.sh ${release} ovs
"""
}
} catch (e) {
currentBuild.result = "FAILED"
throw e
} finally {
// Success or failure, always send notifications
notifyBuild(currentBuild.result, notifyBuildDetails)
}
// https://jenkins.io/blog/2016/07/18/pipline-notifications/
def notifyBuild(String buildStatus = 'STARTED', String details = '') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
// Override default values based on build status
if (buildStatus == 'STARTED') {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESSFUL') {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
summary = "${subject} (${env.BUILD_URL})${details}"
}
// Get token
def slackToken = getSlackToken('sysnet')
// Send notifications
slackSend (color: colorCode, message: summary, teamDomain: 'optdyn', token: "${slackToken}")
}
// get slack token from global jenkins credentials store
@NonCPS
def getSlackToken(String slackCredentialsId){
// id is ID of creadentials
def jenkins_creds = Jenkins.instance.getExtensionList('com.cloudbees.plugins.credentials.SystemCredentialsProvider')[0]
String found_slack_token = jenkins_creds.getStore().getDomains().findResult { domain ->
jenkins_creds.getCredentials(domain).findResult { credential ->
if(slackCredentialsId.equals(credential.id)) {
credential.getSecret()
}
}
}
return found_slack_token
}