This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 868
/
Jenkinsfile
162 lines (161 loc) · 7.16 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
pipeline {
agent any
options {
// Running builds concurrently could cause a race condition with
// building the Docker image.
disableConcurrentBuilds()
// Only keep the last 5 builds.
buildDiscarder(logRotator(numToKeepStr: '5'))
}
stages {
stage('Run Integration Tests') {
when {
anyOf {
changeRequest()
}
}
environment {
//spawns GITHUB_USR and GITHUB_PSW environment variables
GITHUB=credentials('38b2e4a6-167a-40b2-be6f-d69be42c8190')
}
steps {
sh 'docker build \
--build-arg major_release=20.02 \
--build-arg platform=mycroft_mark_1 \
--build-arg pull_request=$BRANCH_NAME \
--build-arg branch_name=$CHANGE_BRANCH \
--build-arg github_api_key=$GITHUB_PSW \
--no-cache \
-t voight-kampff-skill:$BRANCH_NAME .'
echo 'Running Tests'
timeout(time: 60, unit: 'MINUTES')
{
sh 'docker run \
--volume "$HOME/voight-kampff/identity:/root/.mycroft/identity" \
--volume "$HOME/voight-kampff/:/root/allure" \
voight-kampff-skill:$BRANCH_NAME \
-f allure_behave.formatter:AllureFormatter \
-o /root/allure/allure-result --tags ~@xfail'
}
}
post {
always {
echo 'Report Test Results'
echo 'Changing ownership...'
sh 'docker run \
--volume "$HOME/voight-kampff/:/root/allure" \
--entrypoint=/bin/bash \
voight-kampff-skill:$BRANCH_NAME \
-x -c "chown $(id -u $USER):$(id -g $USER) \
-R /root/allure/"'
echo 'Transferring...'
sh 'rm -rf allure-result/*'
sh 'mv $HOME/voight-kampff/allure-result allure-result'
script {
allure([
includeProperties: false,
jdk: '',
properties: [],
reportBuildPolicy: 'ALWAYS',
results: [[path: 'allure-result']]
])
}
unarchive mapping:['allure-report.zip': 'allure-report.zip']
sh (
label: 'Publish Report to Web Server',
script: '''scp allure-report.zip [email protected]:~;
ssh [email protected] "unzip -o ~/allure-report.zip";
ssh [email protected] "rm -rf /var/www/voight-kampff/skills/${BRANCH_NAME}";
ssh [email protected] "mv allure-report /var/www/voight-kampff/skills/${BRANCH_NAME}"
'''
)
echo 'Report Published'
}
failure {
// Send failure email containing a link to the Jenkins build
// the results report and the console log messages to Mycroft
// developers, the developers of the pull request and the
// developers that caused the build to fail.
echo 'Sending Failure Email'
emailext (
attachLog: true,
subject: "FAILURE - Skills Integration Tests - Build ${BRANCH_NAME} #${BUILD_NUMBER}",
body: """
<p>
One or more integration tests failed. Use the
resources below to identify the issue and fix
the failing tests.
</p>
<br>
<p>
<a href='${BUILD_URL}'>
Jenkins Build Details
</a>
 (Requires account on Mycroft's Jenkins instance)
</p>
<br>
<p>
<a href='https://reports.mycroft.ai/skills/${BRANCH_ALIAS}'>
Report of Test Results
</a>
</p>
<br>
<p>Console log is attached.</p>""",
replyTo: '[email protected]',
to: '[email protected]',
recipientProviders: [
[$class: 'RequesterRecipientProvider'],
[$class:'CulpritsRecipientProvider'],
[$class:'DevelopersRecipientProvider']
]
)
}
success {
// Send success email containing a link to the Jenkins build
// and the results report to Mycroft developers, the developers
// of the pull request and the developers that caused the
// last failed build.
echo 'Sending Success Email'
emailext (
subject: "SUCCESS - Skills Integration Tests - Build ${BRANCH_NAME} #${BUILD_NUMBER}",
body: """
<p>
All integration tests passed. No further action required.
</p>
<br>
<p>
<a href='${BUILD_URL}'>
Jenkins Build Details
</a>
 (Requires account on Mycroft's Jenkins instance)
</p>
<br>
<p>
<a href='https://reports.mycroft.ai/skills/${BRANCH_ALIAS}'>
Report of Test Results
</a>
</p>""",
replyTo: '[email protected]',
to: '[email protected]',
recipientProviders: [
[$class: 'RequesterRecipientProvider'],
[$class:'CulpritsRecipientProvider'],
[$class:'DevelopersRecipientProvider']
]
)
}
}
}
}
post {
cleanup {
sh(
label: 'Docker Container and Image Cleanup',
script: '''
docker container prune --force;
docker image prune --force;
'''
)
}
}
}