-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkinsfile-gestpred
78 lines (70 loc) · 3.03 KB
/
jenkinsfile-gestpred
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
pipeline {
environment {
branchname = env.BRANCH_NAME.toLowerCase()
registryCredential = 'jenkins_registry'
}
agent { kubernetes {
label 'builder'
defaultContainer 'builder'
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '15', artifactNumToKeepStr: '15'))
disableConcurrentBuilds()
skipDefaultCheckout()
}
stages {
stage('CheckOut') {
steps { checkout scm }
}
stage('Build') {
when { anyOf { branch 'main'; branch 'homolog'; branch 'php-fpm-hom'; branch 'php-fpm-prod'; } }
steps {
script {
imagename1 = "registry.sme.prefeitura.sp.gov.br/wordpress/${env.branchname}/gestpred"
dockerImage1 = docker.build(imagename1, "-f Dockerfile .")
docker.withRegistry( 'https://registry.sme.prefeitura.sp.gov.br', registryCredential ) {
dockerImage1.push()
}
sh "docker rmi $imagename1"
}
}
}
stage('Deploy Prod'){
when { anyOf { branch 'main'; branch 'php-fpm-prod'; } }
steps {
script{
if ( env.branchname == 'main' ) {
withCredentials([string(credentialsId: 'aprovadores-wordpress', variable: 'aprovadores')]) {
timeout(time: 24, unit: "HOURS") {
input message: 'Deseja realizar o deploy?', ok: 'SIM', submitter: "${aprovadores}"
}
}
}
withCredentials([file(credentialsId: 'config_wordpress', variable: 'config')]){
sh('if [ -f '+"$home"+'/.kube/config ];then rm -f '+"$home"+'/.kube/config; fi')
sh('cp $config '+"$home"+'/.kube/config')
sh 'kubectl rollout restart deployment/prod-gestpred -n prod-gestpred'
sh('if [ -f '+"$home"+'/.kube/config ];then rm -f '+"$home"+'/.kube/config; fi')
}
}
}
}
stage('Deploy Hom'){
when { anyOf { branch 'homolog'; branch 'php-fpm-hom'; } }
steps {
script{
withCredentials([file(credentialsId: 'config_wordpress', variable: 'config')]){
sh('if [ -f '+"$home"+'/.kube/config ];then rm -f '+"$home"+'/.kube/config; fi')
sh('cp $config '+"$home"+'/.kube/config')
sh 'kubectl rollout restart deployment/hom-gestpred -n hom-gestpred'
sh('if [ -f '+"$home"+'/.kube/config ];then rm -f '+"$home"+'/.kube/config; fi')
}
}
}
}
}
post {
always { sh('if [ -f '+"$home"+'/.kube/config ];then rm -f '+"$home"+'/.kube/config; fi') }
}
}