-
Notifications
You must be signed in to change notification settings - Fork 0
/
oldJenkinsFile
68 lines (65 loc) · 2.1 KB
/
oldJenkinsFile
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
pipeline {
agent any
parameters {
choice(name: 'action', choices: ['apply', 'destroy'], description: 'Select the Terraform action to perform')
}
environment {
AWS_REGION = 'ap-south-1'
}
stages {
stage('Checkout') {
steps {
git branch: 'InfraFor3TierArchitecture', url: 'https://github.com/akshatmiglani/Three-Tier-Architecture-for-AWS-using-Terraform'
}
}
stage('Check AWS Credentials') {
steps {
withCredentials([aws(credentialsId: 'aws-creds')]) {
sh 'aws sts get-caller-identity'
}
}
}
stage('Terraform init') {
steps {
sh 'terraform init -reconfigure'
}
}
stage('Plan') {
steps {
withCredentials([aws(credentialsId: 'aws-creds')]){
sh 'terraform plan'
}
}
}
stage('Terraform Action') {
when {
expression { params.action == 'apply' || params.action == 'destroy' }
}
steps {
withCredentials([aws(credentialsId: 'aws-creds')]) {
sh "terraform ${params.action} --auto-approve"
}
}
}
stage('Capture Terraform Output') {
steps {
withCredentials([aws(credentialsId: 'aws-creds')]) {
script {
def output = sh(script: 'terraform output -json', returnStdout: true).trim()
writeFile file: 'terraform_output.json', text: output
}
}
}
}
stage('Send Email') {
steps {
emailext(
to: '[email protected]',
subject: "Terraform Output from Jenkins Pipeline",
body: "Please find the attached Terraform output.",
attachmentsPattern: 'terraform_output.json'
)
}
}
}
}