-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
80 lines (72 loc) · 2.93 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
pipeline {
agent any
parameters {
booleanParam(name: 'PLAN_TERRAFORM', defaultValue: false, description: 'Check to plan Terraform changes')
booleanParam(name: 'APPLY_TERRAFORM', defaultValue: false, description: 'Check to apply Terraform changes')
booleanParam(name: 'DESTROY_TERRAFORM', defaultValue: false, description: 'Check to apply Terraform changes')
}
stages {
stage('Clone Repository') {
steps {
// Clean workspace before cloning (optional)
deleteDir()
// Clone the Git repository
git branch: 'main',
url: 'https://github.com/SiThuKyawTint-GuGu/infrastructure.git'
sh "ls -lart"
}
}
stage('Terraform Init') {
steps {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-crendentails-gugu']]){
dir('infra') {
sh 'echo "=================Terraform Init=================="'
sh 'terraform init'
}
}
}
}
stage('Terraform Plan') {
steps {
script {
if (params.PLAN_TERRAFORM) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-crendentails-gugu']]){
dir('infra') {
sh 'echo "=================Terraform Plan=================="'
sh 'terraform plan'
}
}
}
}
}
}
stage('Terraform Apply') {
steps {
script {
if (params.APPLY_TERRAFORM) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-crendentails-gugu']]){
dir('infra') {
sh 'echo "=================Terraform Apply=================="'
sh 'terraform apply -auto-approve'
}
}
}
}
}
}
stage('Terraform Destroy') {
steps {
script {
if (params.DESTROY_TERRAFORM) {
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'aws-crendentails-gugu']]){
dir('infra') {
sh 'echo "=================Terraform Destroy=================="'
sh 'terraform destroy -auto-approve'
}
}
}
}
}
}
}
}