-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile
65 lines (65 loc) · 2.54 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
pipeline {
agent any
tools {
terraform "terraform_v1.0.11"
}
stages{
stage("Clean Workspace") {
steps {
slackSend channel: "#ci-cd", color: "#5B5F68", message: ":warning: Jenkins trabalhando...Build Started ${desafio} - `${env.JOB_NAME}` #${env.BUILD_NUMBER}:\n(<${env.BUILD_URL}|Open>)", tokenCredentialId: "jenkins-slack"
echo "Limpando Workspace"
echo "O ${desafio} será executado..."
cleanWs() /* clean up our workspace */
}
}
stage("Git Checkout"){
steps{
echo "Clone do repositório Terraform"
sh "git clone git@github.com:santospedroh/desafio-iac-aws.git"
}
}
stage("Terraform Init"){
steps{
dir("desafio-iac-aws/${desafio}"){
echo "Iniciando módulos e providers"
sh "pwd"
sh "ls -ltr"
sh "terraform init"
}
}
}
stage("Terraform Plan"){
steps{
dir("desafio-iac-aws/${desafio}"){
echo "Executando plano de provisionamento"
sh "terraform plan | tee -a terraform_plan.txt"
slackUploadFile channel: "#ci-cd", filePath: "terraform_plan.txt", initialComment: ":page_facing_up: Terraform execution plan - ${desafio} - `${env.JOB_NAME}` #${env.BUILD_NUMBER}"
}
}
}
stage("Terraform Apply"){
steps{
dir("desafio-iac-aws/${desafio}"){
echo "Provisionando a infra-estrutura"
sh "pwd"
sh "ls -ltr"
sh "terraform apply -auto-approve"
}
}
}
}
post {
success {
echo "SUCCESS"
slackSend channel: "#ci-cd", color: "#157B22", message: ":white_check_mark: Deu Bom!!! Build Deployed Successfully ${desafio} - `${env.JOB_NAME}` #${env.BUILD_NUMBER}:\n(<${env.BUILD_URL}|Open>)", tokenCredentialId: "jenkins-slack"
}
failure {
echo "ERROR"
slackSend channel: "#ci-cd", color: "#C81414", message: ":red_circle: Deu ruim... Build Failed ${desafio} - `${env.JOB_NAME}` #${env.BUILD_NUMBER}:\n(<${env.BUILD_URL}|Open>)", tokenCredentialId: "jenkins-slack"
}
always {
echo "One way or another, I have finished"
deleteDir() /* clean up our workspace */
}
}
}