forked from genialis/resolwe-bio-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
188 lines (172 loc) · 8.86 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
throttle(["resolwe_bio_py"]) {
// NOTE: Tests could hang unexpectedly and never release the Jenkins executor. Thus we set a
// general timeout for tests' execution.
timeout(time: 20, unit: "MINUTES") {
node {
def workspace_dir = pwd()
// Genialis Base branch with which to run the End-to-End tests.
def genialis_base_e2e_tests_branch = "master"
// Directory where to check out the given branch of Genialis Base.
def genialis_base_dir = "genialis-base"
// NOTE: To avoid exceeding the maximum allowed shebang lenght when calling pip due
// very long paths of Jenkins' workspaces, we need to set a shorter Tox's working
// directory path.
// More info: http://tox.readthedocs.io/en/latest/example/jenkins.html#avoiding-the-path-too-long-error-with-long-shebang-lines
def tox_workdir = "${env.HOME}/.tox-${env.BUILD_TAG}"
// Extra arguments passed to Tox.
def tox_extra_args = ""
if (genialis_base_e2e_tests_branch == "master") {
// NOTE: If we are running End-to-End tests with Genialis Base's "master" branch,
// we need to allow installing pre-releases with the pip command.
tox_extra_args += "--pre"
}
// Path of the JUnit report.
def junit_report_file = "${genialis_base_dir}/.reports/resdk_e2e_report.xml"
try {
stage("Checkout") {
// Clean up the workspace directory to ensure we will do a clean git check out.
deleteDir()
// Check out the same revision as this script is loaded from.
checkout scm
// Check if the pull request is up to date.
if (env.CHANGE_TARGET) {
git_change_target_merge_base = sh (
script: "git merge-base HEAD origin/${env.CHANGE_TARGET}",
returnStdout: true
).trim()
git_change_target_sha = sh (
script: "git rev-parse origin/${env.CHANGE_TARGET}",
returnStdout: true
).trim()
if (git_change_target_merge_base != git_change_target_sha) {
error(
"""
Pull request is not up-to-date!
Please, rebase your pull request on top of '${env.CHANGE_TARGET}'
(commit: ${git_change_target_sha}).
""".stripIndent()
)
}
}
}
stage("Prepare (E2E)") {
// Check if we trust the author who has submitted this change or if a branch
// from the main repository is being built.
// NOTE: This is necessary since we don't want to expose Genialis Base code
// base to unauthorized people.
// NOTE: This is a work-around until the GitHub Branch Source Plugin authors
// implement a way to configure which pull requests from forked repositories
// are trusted and which not. More info at:
// https://github.com/jenkinsci/github-branch-source-plugin/pull/96
// https://issues.jenkins-ci.org/browse/JENKINS-36240
def change_author = env.CHANGE_AUTHOR
def trusted_authors = [
"AGregorc",
"JureZmrzlikar",
"acopar",
"dblenkus",
"gregorjerse",
"jkokosar",
"jvrakor",
"mstajdohar",
"mzganec",
"robertcv",
"romunov",
]
if (change_author != null && ! trusted_authors.contains(change_author)) {
// NOTE: The change_author variable equals null if a branch from the main
// repository is being built.
error(
"""
User '${change_author}' is not yet trusted to build pull requests!
Please, contact maintainers.
""".stripIndent()
)
}
// Check out the given branch of Genialis Base.
dir(genialis_base_dir) {
git (
[url: "https://github.com/genialis/genialis-base.git",
branch: "${genialis_base_e2e_tests_branch}",
credentialsId: "c89baeb1-9818-4627-95fd-50eeb3677a39",
changelog: false,
poll: false]
)
}
// Create an empty configuration schema to avoid an error about it not being
// available when calling manage.py.
dir(genialis_base_dir) {
sh "mkdir -p frontend/genjs/schema && \
echo '{}' > frontend/genjs/schema/configuration.json"
}
}
stage("Test (E2E)") {
// Run End-to-End tests.
dir(genialis_base_dir) {
withEnv([
"GENESIS_POSTGRESQL_USER=postgres",
// NOTE: These ports must correspond to project's services running on
// the Jenkins server.
"GENESIS_POSTGRESQL_PORT=55440",
"GENESIS_ES_PORT=59210",
"GENESIS_REDIS_PORT=56390",
// Set database name and Redis prefix to a unique value so multiple
// instances can run at the same time.
// NOTE: Genialis Base's Django settings automatically set the
// ELASTICSEARCH_INDEX_PREFIX to 'test_' if the 'manage.py test'
// command is run. Additionally, 'resolwe.elastic' app's logic also
// automatically appends a random ID to test index prefixes to avoid
// index name clashes.
"GENESIS_POSTGRESQL_NAME=${env.BUILD_TAG}",
"GENESIS_MANAGER_REDIS_PREFIX=genialis-base.manager.${env.BUILD_TAG}",
"GENESIS_RESDK_PATH=${workspace_dir}",
"TOX_WORKDIR=${tox_workdir}"
]) {
lock (resource: "resolwe-bio-py-e2e-lock-redis10") {
withEnv([
"GENESIS_REDIS_DATABASE=10"
]) {
// NOTE: End-to-End tests could hang unexpectedly and lock the
// resource indefinitely thus we have to set a timeout on their
// execution time.
timeout(time: 15, unit: "MINUTES") {
sh "tox -e py36-e2e-resdk ${tox_extra_args}"
}
}
}
}
}
if (! fileExists(junit_report_file)) {
error "JUnit report not found at '${junit_report_file}'."
}
}
stage("Clean") {
// Clean up the workspace directory after a successful build to free the disk
// space.
deleteDir()
}
} catch (e) {
currentBuild.result = "FAILED"
// Report failures only when testing the "master" branch.
if (env.BRANCH_NAME == "master") {
notifyFailed()
}
throw e
} finally {
// Record JUnit report.
if (fileExists(junit_report_file)) {
junit junit_report_file
}
// Manually remove Tox's working directory since it is created outside Jenkins's
// workspace.
sh "rm -rf ${tox_workdir}"
}
}
}
}
def notifyFailed() {
slackSend(
color: "#FF0000",
message: "FAILED: Job ${env.JOB_NAME} (build #${env.BUILD_NUMBER}) ${env.BUILD_URL}"
)
}