-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
131 lines (130 loc) · 5.15 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
pipeline {
agent any
options {
checkoutToSubdirectory('poem-react')
skipStagesAfterUnstable()
}
environment {
PROJECT_DIR="poem-react"
}
stages {
stage ('Prepare containers') {
steps {
script
{
try
{
echo 'Prepare containers...'
sh '''
cd $WORKSPACE/$PROJECT_DIR/testenv/
docker-compose up -d --build
let i=1
while (( $i <= 5 ))
do
sleep 5
container_web_running=$(docker ps -f name=poem-react-tests-webapp -f status=running -q)
container_db_running=$(docker ps -f name=poem-react-tests-postgres10 -f status=running -q)
if [[ ! -z "$container_web_running" && ! -z "$container_db_running" ]]
then
docker exec -i poem-react-tests-webapp /home/jenkins/poem-install.sh
exit $?
else
echo "not running"
fi
(( i++ ))
done
exit 1
'''
}
catch (Exception err)
{
echo 'Failed preparation of containers...'
echo err.toString()
sh 'exit 1'
}
}
}
}
stage ('Execute tests') {
parallel {
stage ('Execute backend tests') {
steps {
script
{
try
{
echo 'Executing backend tests...'
sh '''
sleep 5
containers_running=$(docker ps -f name=poem-react-tests -f status=running -q)
if [ ! -z "$containers_running" ]
then
echo "Backend container running"
docker exec -i poem-react-tests-webapp /home/jenkins/execute-backend-tests.sh
exit $?
else
echo "not running"
exit 1
fi
'''
}
catch (Exception err)
{
echo 'Backend tests failed...'
echo err.toString()
sh 'exit 1'
}
}
junit 'poem-react/junit-backend.xml'
}
}
stage ('Execute frontend tests') {
steps {
script
{
try
{
echo 'Executing frontend tests...'
sh '''
sleep 5
containers_running=$(docker ps -f name=poem-react-tests -f status=running -q)
if [ ! -z "$containers_running" ]
then
echo "Frontend container running"
docker exec -i poem-react-tests-webapp /home/jenkins/execute-frontend-tests.sh
exit $?
else
echo "not running"
exit 1
fi
'''
}
catch (Exception err)
{
echo 'Frontend tests failed...'
echo err.toString()
sh 'exit 1'
}
}
junit 'poem-react/junit-frontend.xml'
}
}
}
}
stage ('Generating reports') {
steps {
publishCoverage adapters: [coberturaAdapter(path: 'poem-react/coverage-backend.xml, poem-react/cobertura-coverage.xml', mergeToOneReport: true)]
}
}
}
post {
always {
echo 'Teardown containers...'
sh '''
cd $WORKSPACE/$PROJECT_DIR/testenv/
docker-compose down
'''
cleanWs()
}
}
}