-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
76 lines (69 loc) · 2.72 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
pipeline {
parameters {
string(name: 'environment', defaultValue: 'aws', description: 'Workspace for the deployment')
string(name: 'branch', defaultValue: 'dev', description: 'branch name')
}
environment {
AWS_ACCESS_KEY_ID = credentials('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = credentials('AWS_SECRET_ACCESS_KEY')
}
agent any
////
stages {
stage('Build') {
steps{
sh 'ls -al'
sh "echo '${branch}'"
sh 'cd package && npm ci --omit peer --loglevel verbose && npm run build:prod --loglevel verbose'
sh 'cd iframe && npm install --loglevel verbose && npm ci --loglevel verbose && npm run build:prod --loglevel verbose'
sh 'ls -al iframe/build/'
}
}
stage('TF - Init') {
steps {
script {
if (branch == 'dev') {
sh 'pwd; cd terraform_dev; terraform init -input=false'
}
if (branch == 'master'){
sh 'pwd; cd terraform_prod; terraform init -input=false'
} else {
sh "echo 'Wrong Branch!!'"
}
}
}
}
stage('TF - Plan') {
steps {
script {
if (branch == 'dev') {
sh 'cd terraform_dev; terraform workspace select ${environment} || terraform workspace new ${environment} '
sh 'cd terraform_dev; terraform plan -input=false -out tfplan'
sh 'cd terraform_dev; terraform show -no-color tfplan > tfplan.txt'
}
if (branch == 'master') {
sh 'cd terraform_prod; terraform workspace select ${environment} || terraform workspace new ${environment} '
sh 'cd terraform_prod; terraform plan -input=false -out tfplan'
sh 'cd terraform_prod; terraform show -no-color tfplan > tfplan.txt'
} else {
sh "echo 'Wrong Branch!!'"
}
}
}
}
stage('Deploy - Dev') {
steps {
script {
if (branch == 'dev') {
sh 'pwd;cd terraform_dev ; terraform apply -input=false tfplan'
}
if (branch == 'master') {
sh 'pwd;cd terraform_prod ; terraform apply -input=false tfplan'
} else {
sh "echo 'Wrong Branch!!'"
}
}
}
}
}
}