-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjenkinsfile-acessos
142 lines (125 loc) · 6.08 KB
/
jenkinsfile-acessos
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
pipeline {
environment {
branchname = env.BRANCH_NAME.toLowerCase()
kubeconfig = getKubeconf(env.branchname)
registryCredential = 'jenkins_registry'
namespace = "${env.branchname == 'development' ? 'acessos-dev' : env.branchname == 'preprod' ? 'acessos-preprod' : env.branchname == 'release' ? 'acessos-hom' : env.branchname == 'release-r2' ? 'acessos-hom2' : 'acessos-prd' }"
}
agent { kubernetes {
label 'builder'
defaultContainer 'builder'
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '5'))
disableConcurrentBuilds()
skipDefaultCheckout()
}
stages {
stage('CheckOut') {
steps { checkout scm }
}
stage('Sonar') {
agent { kubernetes {
label 'dotnet6-sonar'
defaultContainer 'dotnet6-sonar'
}
}
when { anyOf { branch 'ci/testesunitarios'; branch 'release'; } }
steps {
checkout scm
script{
withSonarQubeEnv('sonarqube-local'){
sh 'dotnet-sonarscanner begin /k:"SME-Acessos"'
sh 'dotnet build SME.Acessos.Api/SME.Acessos.Api.csproj'
sh 'dotnet test SME.Acessos.TesteIntegracao --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
sh 'dotnet-sonarscanner end'
}
}
}
}
stage('Build') {
when { anyOf { branch 'master'; branch 'preprod'; branch 'main'; branch "story/*"; branch 'development'; branch 'develop'; branch 'release'; branch 'homolog'; branch 'homolog-r2'; } }
steps {
script {
imagename1 = "registry.sme.prefeitura.sp.gov.br/${env.branchname}/sme-acessos"
dockerImage1 = docker.build(imagename1, "-f SME.Acessos.Api/Dockerfile .")
docker.withRegistry( 'https://registry.sme.prefeitura.sp.gov.br', registryCredential ) {
dockerImage1.push()
}
sh "docker rmi $imagename1"
}
}
}
stage('Deploy'){
when { anyOf { branch 'master'; branch 'preprod'; branch 'main'; branch 'development'; branch 'release'; branch 'release-r2'; } }
steps {
script{
if ( env.branchname == 'main' || env.branchname == 'master_' ) {
withCredentials([string(credentialsId: 'aprovadores-acessos', variable: 'aprovadores')]) {
timeout(time: 24, unit: "HOURS") {
input message: 'Deseja realizar o deploy?', ok: 'SIM', submitter: "${aprovadores}"
}
}
}
withCredentials([file(credentialsId: "${kubeconfig}", 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/sme-acessos -n ${namespace}"
sh('if [ -f '+"$home"+'/.kube/config ];then rm -f '+"$home"+'/.kube/config; fi')
}
}
}
}
stage('Flyway') {
agent { kubernetes {
label 'flyway'
defaultContainer 'flyway'
}
}
when { anyOf { branch 'master'; branch 'preprod'; branch 'main'; branch 'development'; branch 'release'; branch 'release-r2'; } }
steps{
withCredentials([string(credentialsId: "flyway_acessos_${branchname}", variable: 'url')]) {
checkout scm
sh 'pwd'
sh 'ls $(pwd)/scripts'
sh 'flyway -X -url=$url -locations="filesystem:scripts" -outOfOrder=true migrate'
//sh 'docker run --rm -v $(pwd)/scripts:/opt/scripts registry.sme.prefeitura.sp.gov.br/devops/flyway:5.2.4 -url=$url -locations="filesystem:/opt/scripts" -outOfOrder=true migrate'
}
}
}
/*stage('Liquibase prd'){
agent { label 'liquibase' }
when { anyOf { branch 'master'; branch 'main'; } }
steps {
checkout scm
script{
if ( env.branchname == 'main' || env.branchname == 'master') {
withCredentials([string(credentialsId: 'aprovadores-sgp', variable: 'aprovadores')]) {
timeout(time: 24, unit: "HOURS") {
input message: 'Deseja realizar o deploy?', ok: 'SIM', submitter: "${aprovadores}"
}
}
}
withCredentials([string(credentialsId: 'liquibase_coresso_prd', variable: 'url')]) {
checkout scm
sh 'docker run -v $(pwd)/liquibase/config.json:/liquibase/config.json -v $(pwd)/scripts_coresso:/liquibase/scripts_coresso registry.sme.prefeitura.sp.gov.br/devops/liquibase:prod update --url=$url --changelog-file=config.json'
}
}
}
}*/
}
post {
always { sh('if [ -f '+"$home"+'/.kube/config ];then rm -f '+"$home"+'/.kube/config; fi')}
}
}
def getKubeconf(branchName) {
if("main".equals(branchName)) { return "config_prod"; }
else if ("preprod".equals(branchName)) { return "config_prod"; }
else if ("master".equals(branchName)) { return "config_prod"; }
else if ("homolog".equals(branchName)) { return "config_release"; }
else if ("homolog-r2".equals(branchName)) { return "config_release"; }
else if ("release".equals(branchName)) { return "config_release"; }
else if ("development".equals(branchName)) { return "config_release"; }
else if ("develop".equals(branchName)) { return "config_release"; }
}