-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsAutomaticTesting
74 lines (70 loc) · 2.89 KB
/
JenkinsAutomaticTesting
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
node('Dev') {
cleanWs()
def repo = 'backend'
def browserstackCredentials = 'bs_free_user_key'
def devMongoUrl = 'cit-dev-mongo-url'
def driverFlags = "${params.DRIVER_FLAGS}"
try {
stage('Prepare') {
def gitBranch = 'master'
def gitLabUrl = 'https://github.com/canitrust/backend.git'
def credentials = 'e7acb748-22b5-47e2-b5c8-f740048baac1'
dir('backend') {
try {
deleteDir()
} catch (err) {
echo "Caught: ${err}"
}
git branch: gitBranch, url: gitLabUrl
echo "Checking out $repo form $gitLabUrl, branch $gitBranch"
}
def gitLabCertUrl = "${env.CIT_GITLAB_CERT_URL}"
dir('test-certs') {
git credentialsId: credentials, url: gitLabCertUrl
echo "Checking out Certs form $gitLabCertUrl"
sh "mkdir ../backend/test_app/src/certs"
sh "cp -r letsencrypt ../backend/test_app/src/certs/"
}
}
echo 'Preparation was successful'
stage('Run') {
dir('backend') {
withCredentials([
usernamePassword(credentialsId: browserstackCredentials, usernameVariable: 'BS_USER', passwordVariable: 'BS_PASS'),
string(credentialsId: devMongoUrl, variable: 'MONGO_URL')
]) {
def cfg = """
DB_URL=$MONGO_URL
DB_DATABASE=Backend
DB_COLL=test_Lab
DB_FAILED_TESTS=failed_tests
API_KEY=$BS_PASS
USER_BS=$BS_USER
"""
writeFile file: './driver/config/.env', text: "${cfg}"
}
sh "./driver.sh ${driverFlags}"
}
}
} catch (e) {
echo 'FAILED'
mail to: "${env.CIT_EMAIL_RECIPIENTS}",
subject: "Failed pipeline ${currentBuild.fullDisplayName}",
body: "Something is wrong with ${env.BUILD_URL}"
throw e
} finally {
echo 'Junit report'
def summary = junit allowEmptyResults: true, testResults: 'backend/driver/junit_output.xml'
echo "Test Summary"
echo "Total: ${summary.totalCount}, Failures: ${summary.failCount}, Successes: ${summary.passCount}"
if (summary.totalCount > 0) {
mail to: "${env.CIT_EMAIL_RECIPIENTS}",
subject: "${summary.totalCount} new tests found ${currentBuild.fullDisplayName}",
body: """
TEST SUMMARY
Total: ${summary.totalCount}, Failures: ${summary.failCount}, Successes: ${summary.passCount}
pipeline ${env.BUILD_URL}
"""
}
}
}