forked from anaxdev/microsvc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
48 lines (48 loc) · 1.47 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
pipeline {
agent any
tools {
terraform 'terraform'
}
parameters {
string(name: 'EC2_INSTANCE_NAME', defaultValue: 'backend', description: 'Name for AWS EC2 Instance')
string(name: 'NAME_PREFIX', defaultValue: 'demo', description: 'The prefix for the name of AWS resources such as VPC, Subnet, Security Group, etc.')
}
stages {
// Git Checkout
// stage('SCM') {
// steps {
// git branch: 'main', url: 'https://github.com/anaxdev/microsvc.git'
// }
// }
// Run Terraform scripts
stage('Server Provision') {
steps {
// Run within terraform directory!
dir('terraform') {
sh 'terraform init'
sh "terraform apply -auto-approve \
-var 'name_prefix=${params.NAME_PREFIX}' \
-var 'ec2_instance_name=${params.EC2_INSTANCE_NAME}'"
}
}
}
// Run Ansible playbooks
stage('Server Configuration') {
steps {
ansiblePlaybook disableHostKeyChecking: true, installation: 'ansible', inventory: 'ansible/inventory.yml', playbook: 'ansible/install-docker.yml'
}
}
stage('Deploy Backend') {
steps {
ansiblePlaybook disableHostKeyChecking: true, installation: 'ansible', inventory: 'ansible/inventory.yml', playbook: 'ansible/deploy-backend.yml'
}
}
stage('Backend Url') {
steps {
dir('terraform') {
sh 'echo Backend Url = http://$(terraform output --raw server_ip)'
}
}
}
}
}