-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from prefeiturasp/homolog
Atualização 10/08/2021
- Loading branch information
Showing
5 changed files
with
224 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
API_MONGO_URI=localhost:27017 | ||
FLASK_APP=api.py | ||
# Caso tenha integração com o sentry, descomente a linha abaixo e coloque a URL | ||
# SENTRY_URL=http://sua_url_do_sentry/2 | ||
# SENTRY_ENVIRONMENT=Development |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
pipeline { | ||
environment { | ||
branchname = env.BRANCH_NAME.toLowerCase() | ||
kubeconfig = getKubeconf(env.branchname) | ||
registryCredential = 'jenkins_registry' | ||
} | ||
|
||
agent { | ||
node { label 'python-36-pratoaberto' } | ||
} | ||
|
||
options { | ||
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5')) | ||
disableConcurrentBuilds() | ||
skipDefaultCheckout() | ||
} | ||
|
||
stages { | ||
|
||
stage('CheckOut') { | ||
steps { checkout scm } | ||
} | ||
|
||
|
||
|
||
stage('AnaliseCodigo') { | ||
when { branch 'homolog' } | ||
steps { | ||
withSonarQubeEnv('sonarqube-local'){ | ||
sh 'echo "[ INFO ] Iniciando analise Sonar..." && sonar-scanner \ | ||
-Dsonar.projectKey=SME-PratoAberto-API \ | ||
-Dsonar.sources=.' | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
stage('Build') { | ||
when { anyOf { branch 'master'; branch 'main'; branch "story/*"; branch 'development'; branch 'release'; branch 'homolog'; } } | ||
steps { | ||
script { | ||
imagename1 = "registry.sme.prefeitura.sp.gov.br/${env.branchname}/pratoaberto-api" | ||
//imagename2 = "registry.sme.prefeitura.sp.gov.br/${env.branchname}/sme-outra" | ||
dockerImage1 = docker.build(imagename1, "-f Dockerfile .") | ||
//dockerImage2 = docker.build(imagename2, "-f Dockerfile_outro .") | ||
docker.withRegistry( 'https://registry.sme.prefeitura.sp.gov.br', registryCredential ) { | ||
dockerImage1.push() | ||
//dockerImage2.push() | ||
} | ||
sh "docker rmi $imagename1" | ||
//sh "docker rmi $imagename2" | ||
} | ||
} | ||
} | ||
|
||
stage('Deploy'){ | ||
when { anyOf { branch 'master'; branch 'main'; branch 'development'; branch 'release'; branch 'homolog'; } } | ||
steps { | ||
script{ | ||
if ( env.branchname == 'main' || env.branchname == 'master' || env.branchname == 'homolog' || env.branchname == 'release' ) { | ||
sendTelegram("🤩 [Deploy ${env.branchname}] Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nMe aprove! \nLog: \n${env.BUILD_URL}") | ||
timeout(time: 24, unit: "HOURS") { | ||
input message: 'Deseja realizar o deploy?', ok: 'SIM', submitter: 'kelwy_oliveira, anderson_morais, luis_zimmermann, rodolpho_azeredo' | ||
} | ||
withCredentials([file(credentialsId: "${kubeconfig}", variable: 'config')]){ | ||
sh('cp $config '+"$home"+'/.kube/config') | ||
sh 'kubectl rollout restart deployment/pratoaberto-api -n sme-pratoaberto' | ||
sh('rm -f '+"$home"+'/.kube/config') | ||
} | ||
} | ||
else{ | ||
withCredentials([file(credentialsId: "${kubeconfig}", variable: 'config')]){ | ||
sh('cp $config '+"$home"+'/.kube/config') | ||
sh 'kubectl rollout restart deployment/pratoaberto-api -n sme-pratoaberto' | ||
sh('rm -f '+"$home"+'/.kube/config') | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
post { | ||
success { sendTelegram("🚀 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Success \nLog: \n${env.BUILD_URL}console") } | ||
unstable { sendTelegram("💣 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Unstable \nLog: \n${env.BUILD_URL}console") } | ||
failure { sendTelegram("💥 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Failure \nLog: \n${env.BUILD_URL}console") } | ||
aborted { sendTelegram ("😥 Job Name: ${JOB_NAME} \nBuild: ${BUILD_DISPLAY_NAME} \nStatus: Aborted \nLog: \n${env.BUILD_URL}console") } | ||
} | ||
} | ||
def sendTelegram(message) { | ||
def encodedMessage = URLEncoder.encode(message, "UTF-8") | ||
withCredentials([string(credentialsId: 'telegramToken', variable: 'TOKEN'), | ||
string(credentialsId: 'telegramChatId', variable: 'CHAT_ID')]) { | ||
response = httpRequest (consoleLogResponseBody: true, | ||
contentType: 'APPLICATION_JSON', | ||
httpMode: 'GET', | ||
url: 'https://api.telegram.org/bot'+"$TOKEN"+'/sendMessage?text='+encodedMessage+'&chat_id='+"$CHAT_ID"+'&disable_web_page_preview=true', | ||
validResponseCodes: '200') | ||
return response | ||
} | ||
} | ||
def getKubeconf(branchName) { | ||
if("main".equals(branchName)) { return "config_prd"; } | ||
else if ("master".equals(branchName)) { return "config_prd"; } | ||
else if ("homolog".equals(branchName)) { return "config_hom"; } | ||
else if ("release".equals(branchName)) { return "config_hom"; } | ||
else if ("development".equals(branchName)) { return "config_dev"; } | ||
} |
Oops, something went wrong.