-
Notifications
You must be signed in to change notification settings - Fork 4
/
Jenkinsfile.tests
90 lines (82 loc) · 3.77 KB
/
Jenkinsfile.tests
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
pipeline {
environment {
branchname = env.BRANCH_NAME.toLowerCase()
kubeconfig = getKubeconf(env.branchname)
registryCredential = 'jenkins_registry'
}
agent { kubernetes {
label 'python310'
defaultContainer 'python310'
}
}
options {
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
disableConcurrentBuilds()
skipDefaultCheckout()
}
stages {
stage('CheckOut') {
steps { checkout scm }
}
/*stage('AmbienteTestes') {
agent { kubernetes {
label 'builder'
defaultContainer 'builder'
}
}
when {
expression { return env.BRANCH_NAME.startsWith("bug") || env.BRANCH_NAME.startsWith("bugfix") || env.BRANCH_NAME.startsWith("feature") || env.BRANCH_NAME.startsWith("fix") || env.BRANCH_NAME.startsWith("releases") || env.BRANCH_NAME.startsWith("hotfix") }
}
steps {
checkout scm
script {
sh 'if [ ! -z $(docker ps -q --filter "name=terceirizadas-db") ]; then docker rm -f terceirizadas-db; fi'
sh 'docker run -d --rm --cap-add SYS_TIME --name terceirizadas-db -p 5432 --network python-network -e TZ="America/Sao_Paulo" -e POSTGRES_DB=terceirizadas -e POSTGRES_PASSWORD=adminadmin -e POSTGRES_USER=postgres postgres:11-alpine'
}
}
}*/
stage('Testes') {
when {
expression { return env.BRANCH_NAME.startsWith("bug") || env.BRANCH_NAME.startsWith("bugfix") || env.BRANCH_NAME.startsWith("feature") || env.BRANCH_NAME.startsWith("fix") || env.BRANCH_NAME.startsWith("releases") || env.BRANCH_NAME.startsWith("hotfix") }
}
steps {
checkout scm
sh 'pip install psycopg2-binary'
sh 'pip install xlsxwriter'
sh 'pip install pycparser'
sh 'pip install --no-cache-dir -U pip'
sh 'pip install --no-cache-dir pipenv==2023.11.15'
sh 'pip install --user pipenv==2023.11.15'
sh 'pipenv install --dev'
sh 'pipenv run flake8'
sh 'pipenv run pytest'
}
}
}
post {
always { cleanWs notFailBuild: true }
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_release"; }
}