-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-jenkins.sh
executable file
·77 lines (57 loc) · 1.76 KB
/
docker-jenkins.sh
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
#!/bin/bash
CLASS=$1
CONTAINER_NAME="gatling-jenkins-docker"
IMAGE_NAME="gatling-jenkins-docker"
function check_image_exist {
echo -e "\n*** Checking if docker image exists for the gatling... ***\n"
if docker images | grep -w ${IMAGE_NAME}
then
echo -e "\n*** Image already exists. We can run container... ***\n"
else
build_image
fi
}
function delete_old_reports {
rm -rf $WORKSPACE/results/
docker exec $CONTAINER_NAME rm -rf /opt/gatling/results/*
}
function build_image {
echo -e "\n*** Building the image ***\n"
docker build -t ${IMAGE_NAME} .
echo -e "\n*** Finished building the image ***\n"
}
function check_container_exist {
echo -e "\n *** Deleting old unused containers"
docker rm $(docker ps -a | grep 'gatling-jenkins-docker' | awk '{print $3}')
echo -e "\n*** Checking if the container exists ***\n"
if docker ps -a | grep ${CONTAINER_NAME}
then
echo -e "\n*** Container already exists ***\n"
docker start ${CONTAINER_NAME}
else
echo -e "\n*** Running the container ***\n"
start_container_with_Gatling
fi
}
function start_container_with_Gatling {
docker run -t --rm -v $WORKSPACE/conf:/opt/gatling/conf \
-v $WORKSPACE/user-files:/opt/gatling/user-files \
-v $WORKSPACE/results:/opt/gatling/results \
--name $CONTAINER_NAME $IMAGE_NAME
}
function stop_container {
docker stop ${CONTAINER_NAME} /opt/gatling/bin/gatling.sh
}
function run_gatling_test {
docker exec ${CONTAINER_NAME} /opt/gatling/bin/gatling.sh -s $CLASS
}
function copy_gatling_reports_to_workspace {
docker cp ${CONTAINER_NAME}:/opt/gatling/results $WORKSPACE/
}
check_image_exist
check_container_exist
delete_old_reports
start_container_with_Gatling
run_gatling_test
copy_gatling_reports_to_workspace
stop_container