-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
188 lines (146 loc) · 5.89 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
@Library("PipelineLibrary") _
env.JOB_NODE_NAME = 'aws-node-00'
node('aws-node-00') {
ansiColor('xterm') {
WORKSPACE = pwd()
stage('Set default workspace and cleanup') {
echo "WORKSPACE"
echo "${WORKSPACE}"
sh 'rm -rf ${WORKSPACE}/*'
}
stage('Setup Check') {
setupCheck {}
}
stage('Retrieve scm vars') {
def checkoutVars = checkout scm
def commit_id = checkoutVars.GIT_COMMIT
env.GIT_COMMIT = checkoutVars.GIT_COMMIT
env.GIT_BRANCH = checkoutVars.GIT_BRANCH
env.GIT_LOCAL_BRANCH = checkoutVars.GIT_LOCAL_BRANCH
env.GIT_PREVIOUS_COMMIT = checkoutVars.GIT_PREVIOUS_COMMIT
env.GIT_URL = checkoutVars.GIT_URL
}
stage('Checkout ansible repo') {
checkoutRepo('https://github.com/BobbyShaftoe/Ansaform.git', WORKSPACE)
}
stage('Download Terraform') {
def terraform_binary = '${WORKSPACE}/Ansaform/terraform'
def terraform_zip = '${WORKSPACE}/Ansaform/terraform.zip'
sh "curl https://releases.hashicorp.com/terraform/0.12.4/terraform_0.12.4_linux_amd64.zip -o " + terraform_zip
sh "unzip " + terraform_zip + " -d " + '${WORKSPACE}/Ansaform'
sh "chmod ugo+x " + terraform_binary
sh "ls -la *"
}
stage("Terraform plan") {
def ansaform_dir = WORKSPACE + '/Ansaform'
def template_dir = WORKSPACE + '/Ansaform/template'
def terraform = WORKSPACE + '/Ansaform/terraform'
dir("$template_dir") {
sh "pwd"
sh "ls -la"
sh "'${terraform}' init"
sh "'${terraform}' get"
sh "'${terraform}' refresh -var-file=../dev/terraform.tfvars"
sh "'${terraform}' plan -var-file=../dev/terraform.tfvars"
sh "'${terraform}' apply -auto-approve -var-file=../dev/terraform.tfvars"
// sh "./terraform init"
// sh "./terraform get"
// sh "./terraform refresh -var-file=../dev/terraform.tfvars"
// sh "./terraform plan -var-file=../dev/terraform.tfvars"
// sh "./terraform apply -auto-approve -var-file=../dev/terraform.tfvars"
dir("$template_dir") {
sh "'${terraform}' state pull > terraform.tfstate"
}
sh "ls -la " + template_dir
}
}
stage('Ansaform'){
def terraform_statefile_path = WORKSPACE + '/Ansaform/template/terraform.tfstate'
def ansible_dir = WORKSPACE + '/Ansaform/ansible'
withPythonEnv('/opt/virtualenv/py36/bin/python') {
dir("$ansible_dir") {
sh ". /opt/virtualenv/py36/bin/activate"
sh "ansible-playbook -vv -i hosts.ini --extra-vars " +
"terraform_statefile_path='${terraform_statefile_path}' terraform-testing.yml"
}
}
}
stage('Collate all'){
def terraform_statefile_path = WORKSPACE + '/Ansaform/template/terraform.tfstate'
def ansible_dir = WORKSPACE + '/Ansaform/ansible'
def ansaform_reports_dir = WORKSPACE + '/Ansaform/ansible/tests'
def junit2html_dir = WORKSPACE + '/Ansaform/lib/junit2html'
def ansaform_dir = WORKSPACE + '/Ansaform'
def documentation_dir = WORKSPACE + '/Ansaform/documentation'
sh ". /opt/virtualenv/py36/bin/activate"
dir("$ansaform_reports_dir"){
sh "python " + junit2html_dir + "/junit2html.py -m aws-resource-attributes-test-report.xml *"
sh "python " + junit2html_dir + "/junit2html.py aws-resource-attributes-test-report.xml"
}
}
stage('build documentation') {
def documentation_dir = WORKSPACE + '/Ansaform/documentation'
sh ". /opt/virtualenv/py36/bin/activate"
dir("$documentation_dir") {
sh "make html"
}
}
}
}
//node('aws-node-00') {
// ansiColor('xterm') {
// environment {
// JOB_DEFINITION = 'Test'
// }
//
// stage('Set default workspace') {
// echo env.WORKSPACE
//
// }
//
// stage('Retrieve scm vars') {
// def checkoutVars = checkout scm
// def commit_id = checkoutVars.GIT_COMMIT
// env.GIT_COMMIT = checkoutVars.GIT_COMMIT
// env.GIT_BRANCH = checkoutVars.GIT_BRANCH
// env.GIT_LOCAL_BRANCH = checkoutVars.GIT_LOCAL_BRANCH
// env.GIT_PREVIOUS_COMMIT = checkoutVars.GIT_PREVIOUS_COMMIT
// env.GIT_URL = checkoutVars.GIT_URL
// }
//
// stage('Checkout scm') {
// checkout scm
// }
//
// stage('Checkout ansible repo') {
// checkoutRepo('https://github.com/BobbyShaftoe/Ansaform.git')
// }
//
// stage('Download Terraform') {
//
// def out='$(pwd)/Ansaform/terraform'
// sh "curl https://releases.hashicorp.com/terraform/0.12.4/terraform_0.12.4_linux_amd64.zip -o " + out
// sh "chmod ugo+x " + out
// sh "ls -la *"
//
// }
//
// stage('Setup Check') {
// setupCheck {}
// }
//
// stage("Terraform plan") {
// def ansaform_dir='$(pwd)/Ansaform'
// dir(ansaform_dir) {
// sh "pwd"
// sh "ls -la"
//
// sh "terraform init template"
// sh "terraform get template"
// sh "terraform plan -var-file=../dev/terraform.tfvars template"
// }
// }
//
//
// }
//}