-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
102 lines (92 loc) · 3.82 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
pipeline {
agent any
parameters {
choice(name: 'aws_region', choices: 'eu-west-1\nus-east-1', description: 'The name of the AWS region')
choice(name: 'ec2_instance_type', choices: 't2.micro\nm3.medium', description: 'The EC2 instance type')
string(name: 'ec2_key_name', defaultValue: '', description: 'The name of your EC2 key pair')
string(name: 'meta_name', defaultValue: '', description: 'A name describing the deployment')
string(name: 'meta_owner_name', defaultValue: '', description: 'Your name')
string(name: 'meta_owner_email', defaultValue: '', description: 'Your email address')
string(name: 'meta_owner_department', defaultValue: 'Development', description: 'Your department')
}
environment {
AWS_ACCESS_KEY_ID = credentials('jenkins-aws-secret-key-id')
AWS_SECRET_ACCESS_KEY = credentials('jenkins-aws-secret-access-key')
AWS_REGION = "${params.aws_region}"
}
stages {
stage('Init') {
steps {
echo 'Initialize project.'
sh 'make init'
echo 'Create terraform.tfvars.json.'
script {
def json = readJSON text: '{}'
json.aws_region = params.aws_region.toString()
json.ec2_instance_type = params.ec2_instance_type.toString()
json.ec2_key_name = params.ec2_key_name.toString()
json.meta_namespace = "${env.JOB_NAME.replaceAll('/','-').replaceAll(' ','')}-${params.meta_owner_email}".toString()
json.meta_name = params.meta_name.toString()
json.meta_owner_name = params.meta_owner_name.toString()
json.meta_owner_email = params.meta_owner_email.toString()
json.meta_owner_department = params.meta_owner_department.toString()
writeJSON file: 'terraform.tfvars.json', json: json
archiveArtifacts artifacts: 'terraform.tfvars.json'
stash includes: 'terraform.tfvars.json', name: 'terraform-vars'
}
}
}
/*
stage('Test') {
environment {
AWS_ACCESS_KEY_ID = credentials('jenkins-aws-testing-secret-key-id')
AWS_SECRET_ACCESS_KEY = credentials('jenkins-aws-testing-secret-access-key')
}
steps {
echo 'Run infrastructure (integration) tests.'
sh 'make test'
}
}
*/
stage('Plan') {
steps {
unstash name: 'terraform-vars'
echo 'Plan infrastructure.'
sh "make plan NAMESPACE='${env.JOB_NAME}-${params.meta_owner_email}'"
archiveArtifacts artifacts: 'tfplan'
stash includes: 'tfplan', name: 'terraform-plan'
}
}
stage('Deploy') {
steps {
echo 'Deploy infrastructure.'
unstash name: 'terraform-plan'
unstash name: 'terraform-vars'
sh "make deploy NAMESPACE='${env.JOB_NAME.replaceAll('/','-').replaceAll(' ','')}-${params.meta_owner_email}'"
}
}
stage('Smoke-Test') {
steps {
echo 'Run infrastructure (smoke) tests.'
sh 'make smoke-test'
}
}
stage('Describe') {
steps {
echo 'Describe infrastructure.'
sh "make describe NAMESPACE='${env.JOB_NAME.replaceAll('/','-').replaceAll(' ','')}-${params.meta_owner_email}'"
archiveArtifacts artifacts: 'outputs.json'
}
}
}
/*
post {
success {
mail to: "${params.meta_owner_email}", subject: "Your infrastructure job '${env.JOB_NAME}' is ready :-)", body: "Check the console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"
}
failure {
mail to: "${params.meta_owner_email}", subject: "Your infrastructure job '${env.JOB_NAME}' has failed :-('${env.JOB_NAME}'", body: "Check the console output at <a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"
}
}
*/
}