-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
87 lines (66 loc) · 2.27 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
pipeline {
agent any
parameters {
string defaultValue: '', description: '', name: 'AWS_KEY_PAIR', trim: false
string defaultValue: '', description: '', name: 'ACCESS_KEY', trim: false
string defaultValue: '', description: '', name: 'SECRET_KEY', trim: false
string defaultValue: '', description: '', name: 'SUBNET', trim: false
}
stages {
stage ('Launching Application Servers') {
steps {
sh '''
figlet Launching 2 Application servers
rm -rf workdir ; mkdir workdir ; cd workdir
cp -r ../step1/* .
ansible-playbook playbook.yml --extra-vars "AWS_KEY_PAIR=$AWS_KEY_PAIR ACCESS_KEY=$ACCESS_KEY SECRET_KEY=$SECRET_KEY SUBNET=$SUBNET" > output ;
cat output | grep msg | cut -d':' -f2 | cut -d'"' -f2 > /tmp/ApplicationIPs
cat /tmp/ApplicationIPs
'''
}
}
stage ('Deploying GO LANG APP on Application Servers') {
steps {
sh '''
cd workdir
figlet Creating inventory for golang app
bash -x createInventory.sh # Create inventory for golang app
cp hosts /tmp/hosts ; rm -rf * ; cp /tmp/hosts .
figlet hosts file for Application Servers ready
cp -r ../step2/* .
cat hosts
sleep 60
figlet Deploying App on Application Servers
ansible-playbook playbook.yml -i hosts # Deployed go lang Application on 2 AppServers
rm -rf *
'''
}
}
stage ('Launching 1 Nginx Server') {
steps {
sh '''
cd workdir
cp -r ../step3/* .
figlet Launching 1 Nginx server
ansible-playbook playbook.yml --extra-vars "AWS_KEY_PAIR=$AWS_KEY_PAIR ACCESS_KEY=$ACCESS_KEY SECRET_KEY=$SECRET_KEY SUBNET=$SUBNET" > output ; cat output | grep msg | cut -d':' -f2 | cut -d'"' -f2 > /tmp/NginxApp
bash -x createInventory.sh #Create inventory for Nginx App
cp hosts /tmp/hosts ; rm -rf * ; cp /tmp/hosts .
figlet Creating inventory for Nginx Server
cp -r ../step4/* .
for ips in `cat /tmp/ApplicationIPs` ; do echo " - $ips" >> roles/step4/vars/main.yml ; done
cat hosts
sleep 60
'''
}
}
stage ('Configuring Load Balancing between 2 App Servers on Nginx') {
steps {
sh '''
cd workdir
figlet applying Load balancing on Nginx
ansible-playbook playbook.yml -i hosts # Load Balance Application on Nginx
'''
}
}
}
}