forked from edureka-git/DevOpsClassCodes
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathJenkinsfile
54 lines (52 loc) · 1.61 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
pipeline {
agent any
tools {
maven 'M2_HOME'
terraform 'Terraform-1.3.7'
}
environment {
AWS_ACCESS_KEY_ID = '${Access_Key}'
AWS_SECRET_KEY = '${Secret_Key}'
}
stages {
stage('Checkout') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/devopscbabu/DevOpsAddressBook.git']]])
}
}
stage('Compile') {
steps {
sh 'mvn clean package'
}
}
stage('Docker Build') {
steps {
sh 'docker build -t cbabu85/devopsaddressbook .'
}
}
stage('Docker Push') {
steps {
withCredentials([string(credentialsId: 'docker-hub', variable: 'dockerHubPwd')]) {
sh 'docker login -u cbabu85 -p ${dockerHubPwd}'
}
sh 'docker push cbabu85/devopsaddressbook'
}
}
stage('Terraform init') {
steps {
sh 'terraform init'
}
}
stage('Terraform Apply') {
steps {
sh 'terraform apply --auto-approve'
sleep 20
}
}
stage('Docker Deploy using Ansible') {
steps {
ansiblePlaybook credentialsId: 'terraform-docker', disableHostKeyChecking: true, installation: 'ansible', inventory: 'dev.inv', playbook: 'deploy-docker.yml'
}
}
}
}