forked from avalonmediasystem/avalon
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfile
174 lines (153 loc) · 5.33 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
pipeline {
// Jenkins configuration dependencies
//
// Global Tool Configuration:
// Git
//
// This configuration utilizes the following Jenkins plugins:
//
// * Warnings Next Generation
// * Email Extension Plugin
//
// This configuration also expects the following environment variables
// to be set (typically in /apps/ci/config/env:
//
// JENKINS_EMAIL_SUBJECT_PREFIX
// The Email subject prefix identifying the server.
// Typically "[Jenkins - <HOSTNAME>]" where <HOSTNAME>
// is the name of the server, i.e. "[Jenkins - cidev]"
//
// JENKINS_DEFAULT_EMAIL_RECIPIENTS
// A comma-separated list of email addresses that should
// be the default recipients of Jenkins emails.
agent any
options {
// Throttle declarative pipeline so only one Avalon build runs at a time.
throttleJobProperty(
categories: ['throttle_avalon'],
throttleEnabled: true,
throttleOption: 'category'
)
buildDiscarder(
logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
numToKeepStr: '20'))
}
environment {
DEFAULT_RECIPIENTS = "${ \
sh(returnStdout: true, \
script: 'echo $JENKINS_DEFAULT_EMAIL_RECIPIENTS').trim() \
}"
EMAIL_SUBJECT_PREFIX = "${ \
sh(returnStdout: true, script: 'echo $JENKINS_EMAIL_SUBJECT_PREFIX').trim() \
}"
EMAIL_SUBJECT = "$EMAIL_SUBJECT_PREFIX - " +
'$PROJECT_NAME - ' +
'GIT_BRANCH_PLACEHOLDER - ' +
'$BUILD_STATUS! - ' +
"Build # $BUILD_NUMBER"
EMAIL_CONTENT =
'''$PROJECT_NAME - GIT_BRANCH_PLACEHOLDER - $BUILD_STATUS! - Build # $BUILD_NUMBER:
|
|Check console output at $BUILD_URL to view the results.
|
|There were ${TEST_COUNTS,var="fail"} failed tests.
|
|There are ${ANALYSIS_ISSUES_COUNT} static analysis issues in this build.
|
|There were ${TEST_COUNTS,var="skip"} skipped tests.'''.stripMargin()
}
stages {
stage('initialize') {
steps {
script {
// Retrieve the actual Git branch being built for use in email.
//
// For pull requests, the actual Git branch will be in the
// CHANGE_BRANCH environment variable.
//
// For actual branch builds, the CHANGE_BRANCH variable won't exist
// (and an exception will be thrown) but the branch name will be
// part of the PROJECT_NAME variable, so it is not needed.
ACTUAL_GIT_BRANCH = ''
try {
ACTUAL_GIT_BRANCH = CHANGE_BRANCH + ' - '
} catch (groovy.lang.MissingPropertyException mpe) {
// Do nothing. A branch (as opposed to a pull request) is being
// built
}
// Replace the "GIT_BRANCH_PLACEHOLDER" in email variables
EMAIL_SUBJECT = EMAIL_SUBJECT.replaceAll('GIT_BRANCH_PLACEHOLDER - ', ACTUAL_GIT_BRANCH )
EMAIL_CONTENT = EMAIL_CONTENT.replaceAll('GIT_BRANCH_PLACEHOLDER - ', ACTUAL_GIT_BRANCH )
}
}
}
stage('build') {
steps {
sh '''
# Purge any volumes not in use by a container
docker system prune --force --volumes
# Start the Avalon Docker containers for testing
docker-compose up -d test
'''
}
}
stage('test') {
steps {
sh '''
# Unclear why the following line is necessary -- without it, yarn
# almost always seems to encounter an error downloading packages.
# See https://github.com/yarnpkg/yarn/issues/2629#issuecomment-685088015
docker-compose exec -T test bash -c "yarn install --check-files --cache-folder .ycache && rm -rf .ycache"
# Run bundle install
docker-compose exec -T test bash -c "bundle install"
# Run rspec tests, with "documentation" formatter (for the
# console log) and JUnit-formatted output (to a file) for
# Jenkins stats
docker-compose exec -T test bash -c "bundle exec rspec --format documentation --format RspecJunitFormatter --out rspec.xml"
'''
}
post {
always {
// Process JUnit-formatter test output
junit 'rspec.xml'
}
}
}
// stage('static-analysis') {
// steps {
// sh '''
// # Run Rubocop/static analysis tools
// '''
// }
// post {
// always {
// // Collect static analysis reports
// }
// }
// }
}
post {
always {
// Email build results
emailext to: "$DEFAULT_RECIPIENTS",
subject: "$EMAIL_SUBJECT",
body: "$EMAIL_CONTENT"
// Change permissions of the workspace directory to world-writeable
// so Jenkins can delete it. This is needed, because files may be
// written to the directory from the Docker container as the "root"
// user, which Jenkins would not otherwise be able to clean up.
sh '''
docker-compose exec -T test bash -c "chmod --recursive 777 /home/app/avalon"
'''
sh '''
# Stop Avalon Docker containers, using "--volumes" flag to delete
# all volumes
docker-compose down --volumes
'''
// Cleanup workspace
cleanWs()
}
}
}