-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathJenkinsfile
More file actions
74 lines (71 loc) · 2.54 KB
/
Copy pathJenkinsfile
File metadata and controls
74 lines (71 loc) · 2.54 KB
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
pipeline {
agent any
environment {
app_version = 'v1'
rollback = 'false'
}
stages{
stage('Testing All 4 Services'){
steps{
sh '''
cd 1-frontend
pip3 install -r requirements.txt
python3 -m pytest --cov=app --cov-report=term-missing
cd ..
cd 2-chargen
pip3 install -r requirements.txt
python3 -m pytest --cov=app --cov-report=term-missing
cd ..
cd 3-numgen
pip3 install -r requirements.txt
python3 -m pytest --cov=app --cov-report=term-missing
cd ..
cd 4-prizegen
pip3 install -r requirements.txt
python3 -m pytest --cov=app --cov-report=term-missing
cd ..
'''
}
}
stage('Build & Tag'){
steps{
script{
if (env.rollback == 'false'){
sh "docker-compose build --parallel --build-arg ${app_version}"
}
}
}
}
stage('Push Image'){
steps{
script{
if (env.rollback == 'false'){
docker.withRegistry('', 'docker-hub-credentials'){
sh "docker-compose push"
sh "docker system prune -af"
}
}
}
}
}
stage("Configuration Management via Ansible"){
steps{
script{
sh "cd ansible && ansible-playbook -i inventory.yaml playbook.yaml"
}
}
}
stage('Deploy Swarm Stack'){
steps{
sh '''
ssh -oStrictHostKeyChecking=no dontchangethisemailplease@34.105.204.33 << EOF
rm -rf Project2
git clone https://github.com/mrbilalshafiq/Project2.git && cd Project2
export app_version=${app_version}
docker stack deploy --compose-file docker-compose.yaml Project2
echo "Well done, you should be proud of yourself."
'''
}
}
}
}