-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
62 lines (57 loc) · 1.71 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
pipeline {
agent any
stages {
stage('Copy environment') {
steps {
sh 'cp /var/icoworld/.env-fork ./.env'
}
}
stage('Set BUILD_ID') {
steps {
sh 'export BUILD_ID=${BUILD_ID}'
}
}
stage('Start database') {
steps{
echo "Starting db..."
sh 'docker-compose up -d db || echo "The container name "/database" is already in use"'
}
}
stage('Build') {
steps {
sh 'docker-compose build --no-cache app 1>/var/jenkins/buildlog/build-number_$BUILD_ID.txt'
}
}
stage('Testing image ico/backend:${BUILD_ID}') {
steps {
sh('''#!/bin/bash
docker run --name backend-test-$BUILD_ID -d -p 5555:3000 --network=efk_fluentd --env-file /var/icoworld/test.env ico/backend:$BUILD_ID && \\
sleep 30 && \\
RESPONSE=`curl localhost:5555` || exit 2
if [ \$RESPONSE != 'icoWorld' ]; then
echo "stopping container - ${BUILD_ID}"
docker ps -f name=backend-test -q | xargs -r docker container stop
echo "renaming container - ${BUILD_ID}"
docker rename backend-test-$BUILD_ID backend-test-$BUILD_ID_fail
echo "backend did not answer"
exit 1
else
echo "stopping container - ${BUILD_ID}"
docker stop backend-test-$BUILD_ID
echo "removing container - ${BUILD_ID}"
docker rm backend-test-$BUILD_ID
fi
''')
}
}
stage('Deploy') {
steps {
sh('''#!/bin/bash
docker rm -f backend && \\
docker-compose stop app && \\
docker-compose up -d --force-recreate app
''')
}
}
}
}