forked from MycroftAI/mycroft-skills
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
189 lines (188 loc) · 8.76 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
178
179
180
181
182
183
184
185
186
187
188
189
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')
// Some branches have a "/" in their name (e.g. feature/new-and-cool)
// Some commands, such as those tha deal with directories, don't
// play nice with this naming convention. Define an alias for the
// branch name that can be used in these scenarios.
BRANCH_ALIAS = sh(
script: 'echo $BRANCH_NAME | sed -e "s#/#_#g"',
returnStdout: true
).trim()
}
steps {
echo "Pushing to temporary test repo..."
sh 'git remote add mine git+ssh://[email protected]/forslund/mycroft-skills.git || true'
sh 'git push -uf mine ${BRANCH_NAME}'
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=$BRANCH_NAME \
--build-arg repo_url=https://github.com/forslund/mycroft-skills \
--build-arg github_api_key=$GITHUB_PSW \
--no-cache \
-t voight-kampff-skill:${BRANCH_ALIAS} .'
echo 'Running Tests'
timeout(time: 60, unit: 'MINUTES')
{
sh 'docker run \
--volume "$HOME/voight-kampff/identity:/root/.mycroft/identity" \
--volume "$HOME/allure/skills/:/root/allure" \
voight-kampff-skill:${BRANCH_ALIAS} \
-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/allure/skills/:/root/allure" \
--entrypoint=/bin/bash \
voight-kampff-skill:${BRANCH_ALIAS} \
-x -c "chown $(id -u $USER):$(id -g $USER) \
-R /root/allure/"'
echo 'Transferring...'
sh 'rm -rf allure-result/*'
sh 'mv $HOME/allure/skills/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_ALIAS}";
ssh [email protected] "mv allure-report /var/www/voight-kampff/skills/${BRANCH_ALIAS}"
'''
)
echo 'Report Published'
}
failure {
// Send allure report to Pull request
script {
// Create comment for Pull Requests
if (env.CHANGE_ID) {
echo 'Sending PR comment'
pullRequest.comment('Voight Kampff Integration Test Failed ([Results](https://reports.mycroft.ai/skills/' + env.BRANCH_ALIAS + '))')
}
}
// 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 report to Pull request
script {
if (env.CHANGE_ID) {
echo 'Sending PR comment'
pullRequest.comment('Voight Kampff Integration Test Succeeded ([Results](https://reports.mycroft.ai/skills/' + env.BRANCH_ALIAS + '))')
}
}
// 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;
'''
)
}
}
}