-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
149 lines (141 loc) · 5.53 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
/* import shared library */
@Library('jenkins-shared-library')_
pipeline {
agent none
stages {
stage('Check bash syntax') {
agent { docker { image 'koalaman/shellcheck-alpine:stable' } }
steps {
script { bashCheck }
}
}
stage('Check yaml syntax') {
agent { docker { image 'sdesbure/yamllint' } }
steps {
sh 'yamllint --version'
sh 'yamllint \${WORKSPACE}'
}
}
stage('Check markdown syntax') {
agent { docker { image 'ruby:alpine' } }
steps {
sh 'apk --no-cache add git'
sh 'gem install mdl'
sh 'mdl --version'
sh 'mdl --style all --warnings --git-recurse \${WORKSPACE}'
}
}
stage('Prepare ansible environment') {
agent any
environment {
VAULTKEY = credentials('vaultkey')
DEVOPSKEY = credentials('devopskey')
}
steps {
sh 'echo \$VAULTKEY > vault.key'
sh 'cp \$DEVOPSKEY id_rsa'
sh 'chmod 600 id_rsa'
}
}
stage('Test and deploy the application in preproduction') {
agent { docker { image 'registry.gitlab.com/robconnolly/docker-ansible:latest' } }
stages {
stage("Install ansible role dependencies") {
steps {
sh 'ansible-galaxy install -r roles/requirements.yml'
}
}
stage("Ping targeted hosts") {
steps {
sh 'ansible all -m ping -i hosts --private-key id_rsa'
}
}
stage("Verify ansible playbook syntax") {
steps {
sh 'ansible-lint -x 306 install_fake-backend.yml'
sh 'echo "${GIT_BRANCH}"'
}
}
stage("Build docker images on build host") {
when {
expression { GIT_BRANCH == 'origin/dev' }
}
steps {
sh 'ansible-playbook -i hosts --vault-password-file vault.key --private-key id_rsa --tags "build" --limit build install_fake-backend.yml'
}
}
stage("Deploy application in preproduction") {
when {
expression { GIT_BRANCH == 'origin/dev' }
}
steps {
sh 'ansible-playbook -i hosts --vault-password-file vault.key --private-key id_rsa --tags "preprod" --limit preprod install_fake-backend.yml'
}
}
stage("Ensure application is deployed in preproduction") {
when {
expression { GIT_BRANCH == 'origin/dev' }
}
steps {
sh 'ansible-playbook -i hosts --vault-password-file vault.key --tags "preprod" check_deploy_app.yml'
}
}
}
}
stage('Test and deploy the application in production') {
agent { docker { image 'registry.gitlab.com/robconnolly/docker-ansible:latest' } }
stages {
stage("Install ansible role dependencies") {
when {
expression { GIT_BRANCH == 'origin/master' }
}
steps {
sh 'ansible-galaxy install -r roles/requirements.yml'
}
}
stage("Ping targeted hosts") {
when {
expression { GIT_BRANCH == 'origin/master' }
}
steps {
sh 'ansible all -m ping -i hosts --private-key id_rsa'
}
}
stage("Verify ansible playbook syntax") {
when {
expression { GIT_BRANCH == 'origin/master' }
}
steps {
sh 'ansible-lint -x 306 install_fake-backend.yml'
sh 'echo "${GIT_BRANCH}"'
}
}
stage("Deploy application in production") {
when {
expression { GIT_BRANCH == 'origin/master' }
}
steps {
sh 'ansible-playbook -i hosts --vault-password-file vault.key --private-key id_rsa --tags "prod" --limit prod install_fake-backend.yml'
}
}
stage("Ensure application is deployed in production") {
when {
expression { GIT_BRANCH == 'origin/master' }
}
steps {
sh 'ansible-playbook -i hosts --vault-password-file vault.key --tags "prod" check_deploy_app.yml'
}
}
}
}
}
post {
always {
script {
/* Use slackNotifier.groovy from shared library and provide current build result as parameter */
clean
slackNotifier currentBuild.result
}
}
}
}