-
Notifications
You must be signed in to change notification settings - Fork 8
/
Jenkinsfile
170 lines (146 loc) · 4.59 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
#!groovy
import groovy.json.JsonSlurperClassic
notifyBuildDetails = ""
snapAppName = ""
commitId = ""
serenityReportDir = ""
try {
notifyBuild('STARTED')
node("newsnap") {
deleteDir()
stage("Checkout source")
/* Checkout snap repository */
notifyBuildDetails = "\nFailed on Stage - Checkout source"
sh """
rm -rf *
"""
checkout scm
commitId = sh (script: "git rev-parse HEAD", returnStdout: true)
serenityReportDir = "/var/lib/jenkins/www/serenity/${commitId}"
stage("Generate snapcraft.yaml")
sh """
./configure ${env.BRANCH_NAME}
"""
stage("Build snap")
notifyBuildDetails = "\nFailed on Stage - Build snap"
sh """
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
snapcraft
"""
stash includes: "subutai-*_amd64.snap", name: 'snap'
}
node() {
// Start Test-Peer Lock
if (env.BRANCH_NAME == 'dev') {
lock('debian_slave_node') {
unstash "snap"
sh """
scp \$(ls -t ${snapAppName}*_amd64.snap | head -1) admin@${env.debian_slave_node}:/tmp/subutai-dev-latest.snap
"""
// destroy existing management template on test node and install latest available snap
sh """
set +x
ssh admin@${env.debian_slave_node} <<- EOF
set -e
sudo subutai-dev destroy management
if test -f /var/snap/subutai-dev/current/p2p.save; then sudo rm /var/snap/subutai-dev/current/p2p.save; fi
sudo find /var/snap/subutai-dev/common/lxc/tmpdir/ -maxdepth 1 -type f -name 'management-subutai-template_*' -delete
sudo snap install --dangerous --devmode /tmp/subutai-dev-latest.snap
sudo find /tmp -maxdepth 1 -type f -name 'subutai-dev_*' -delete
EOF"""
// install generated management template
sh """
set +x
ssh admin@${env.debian_slave_node} <<- EOF
set -e
sudo subutai-dev import debian-stretch
sudo subutai-dev import management
EOF"""
/* wait until SS starts */
timeout(time: 5, unit: 'MINUTES') {
sh """
set +x
echo "Waiting SS"
while [ \$(curl -k -s -o /dev/null -w %{http_code} 'https://${env.debian_slave_node}:8443/rest/v1/peer/ready') != "200" ]; do
sleep 5
done
"""
}
stage("Integration tests")
deleteDir()
def mvnHome = tool 'M3'
// Run Serenity Tests
notifyBuildDetails = "\nFailed on Stage - Integration tests\nSerenity Tests Results:\n${env.JENKINS_URL}serenity/${commitId}"
git url: "https://github.com/subutai-io/playbooks.git"
sh """
set +e
./run_tests_qa.sh -m ${env.debian_slave_node}
./run_tests_qa.sh -s all
${mvnHome}/bin/mvn integration-test -Dwebdriver.firefox.profile=src/test/resources/profilePgpFF
OUT=\$?
${mvnHome}/bin/mvn serenity:aggregate
cp -rl target/site/serenity ${serenityReportDir}
if [ \$OUT -ne 0 ];then
exit 1
fi
"""
}
} // end if
} // end node
node("newsnap") {
// upload snap to ubuntu store
stage("Upload to Ubuntu Store")
unstash "snap"
notifyBuildDetails = "\nFailed on Stage - Upload to Ubuntu Store"
sh """
snapcraft push \$(ls -t ${snapAppName}*_amd64.snap | head -1 ) --release beta
"""
}
} 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
}