-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline
95 lines (94 loc) · 4.03 KB
/
pipeline
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
pipeline {
agent any
stages {
stage("Making back-up") {
steps {
echo " ==============creating back-up=================="
script {
if (isUnix()) {
sh "docker exec jenk_bot sh -c \"sqlite3 ./notifications.db .dump > dump.sql\""
sh "docker exec jenk_bot sh -c \"tar -cvf backup.tar ./attachments\""
sh "docker exec jenk_bot sh -c \"tar -rvf backup.tar dump.sql\""
sh "docker exec jenk_bot sh -c \"gzip backup.tar\""
sh "docker exec jenk_bot sh -c \"rm dump.sql\""
sh "docker cp ./backup.tar.gz ./storage/backup/backup.tar.gz"
sh "docker exec jenk_bot sh -c \"rm backup.tar.gz\""
} else {
bat "docker exec jenk_bot bash -c \"apt-get update && apt-get install -y sqlite3 && sqlite3 ./notifications.db .dump > dump.sql\""
bat "docker exec jenk_bot bash -c \"tar -cvf backup.tar ./attachments\""
bat "docker exec jenk_bot bash -c \"tar -rvf backup.tar dump.sql\""
bat "docker exec jenk_bot bash -c \"gzip backup.tar\""
bat "docker exec jenk_bot bash -c \"rm dump.sql\""
bat "docker cp jenk_bot:/NotificationBot/backup.tar.gz ./storage/backup/backup.tar.gz"
bat "docker exec jenk_bot bash -c \"rm backup.tar.gz\""
}
}
echo " ==============back-up created succesfully=================="
}
}
stage('Stop old container') {
steps {
echo '===============stopping old container==================='
script {
if (isUnix()) {
sh 'docker stop jenk_bot || true'
} else {
bat 'docker stop jenk_bot || echo off'
}
}
echo '===============old container successfully stopped==================='
}
}
stage('Download git repository') {
steps {
echo '===============downloading git repo==================='
script {
if (isUnix()) {
sh 'rm -rf api_lab2'
sh 'git clone --depth=1 https://github.com/riapush/NotificationBot.git'
sh 'rm -rf api_lab2/.git*'
sh 'ls'
} else {
bat 'powershell Remove-Item NotificationBot -Recurse -Force'
bat 'git clone --depth=1 https://github.com/riapush/NotificationBot.git NotificationBot'
bat 'powershell Remove-Item NotificationBot/.git* -Recurse -Force'
}
}
echo '===============git repo downloaded==================='
}
}
stage('Getting env variables') {
steps {
echo '===============getting env variables==================='
withCredentials([file(credentialsId: 'ENV', variable: 'ENV')]) {
script {
if (isUnix()) {
sh 'cp $ENV ./.env'
sh 'mkdir -p ./storage/backup'
} else {
bat 'powershell Copy-Item %ENV% -Destination ./.env'
bat 'If Not Exist storage\\backup mkdir storage\\backup'
}
}
}
echo '===============got variables succesfully==================='
}
}
}
post {
success {
echo '===============run docker==================='
script {
if (isUnix()) {
sh 'docker build -t notificationbot .'
sh 'docker run --name jenk_bot -d --rm notificationbot'
} else {
bat 'docker build -t notificationbot .'
bat 'docker run --name jenk_bot -d --rm notificationbot'
bat 'If Not Exist storage/dump.sql powershell New-Item storage/dump.sql'
}
}
echo '===============docker container is running successfully==================='
}
}
}