-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
56 lines (53 loc) · 1.52 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
pipeline {
agent any
stages {
stage('Stage 1') {
steps {
echo "======== executing stage ========"
echo 'Hello world!'
}
}
stage("getting code") {
steps {
echo "======== executing stage ========"
git url: 'https://github.com/Malek-Zaag/CICD-pipeline-with-Ansible-and-AWS.git', branch: 'main', credentialsId: 'Github-creds'
sh "ls -ltr"
sh "java --version"
}
}
stage("checking terraform and provisionning servers") {
steps {
echo "======== executing stage ========"
sh "terraform --version"
dir("./Infrastructure/EC2/") {
sh "terraform init --upgrade"
}
dir("./Infrastructure/EC2/") {
sh "terraform apply --auto-approve"
}
}
}
stage("Adding public IPs to /etc/hosts") {
steps {
dir("./Infrastructure/EC2/") {
sh "terraform output > file.txt"
sh "cut -d '=' -f 2 file.txt"
sh "sed 's/\"//g; s/=//g' file.txt > res.txt"
sh 'awk \' { t = $1; $1 = $2; $2 = t; print; } \' res.txt > f.txt'
sh "cat f.txt"
sh 'sudo -- sh -c "cat f.txt >> /etc/hosts"'
}
}
}
stage("applying ansible playbooks for configuring files") {
steps {
echo "======== executing stage ========"
sh "ansible --version"
dir("./Ansible/") {
sh "ansible-playbook -i hosts app-playbook.yaml"
sh "ansible-playbook -i hosts db-playbook.yaml"
}
}
}
}
}