Repository navigation
Expand file tree
/
Copy pathjenkinsfile
More file actions
74 lines (73 loc) · 2.33 KB
/
Copy pathjenkinsfile
File metadata and controls
74 lines (73 loc) · 2.33 KB
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
pipeline {
agent any
environment {
BUILD = "${env.BUILD_NUMBER}"
SLACK_TOKEN = credentials('slack-token')
}
stages {
stage('Clone repository') {
steps {
git url: 'https://github.com/snoopykill/PythonFlaskMySQLApp.git'
}
}
stage('Checking repository'){
steps {
sh "ls -l"
}
}
stage('Build docker') {
steps {
script {
dockerImage = docker.build("snoopykill/python-app")
}
}
}
stage('Push docker') {
steps {
script {
docker.withRegistry('https://registry.hub.docker.com', 'docker-hub-credentials') {
dockerImage.push("${env.BUILD_NUMBER}")
dockerImage.push("latest")
}
}
}
}
stage('Docker compose') {
steps {
script {
sh """
docker-compose down
docker-compose up -d
"""
}
}
}
stage('Test site by Apache Bench') {
steps {
script {
sh """
ab -n 100 -c 10 -r http://127.0.0.1:50000/ > project.txt
curl -F file=@project.txt -F channels=CLBKQPFB5 -F token=${env.SLACK_TOKEN} https://slack.com/api/files.upload
"""
}
}
}
}
post {
success {
slackSend (color: '#00FF00', message: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}
failure {
script {
BUILD = "${env.BUILD_NUMBER.toInteger() - 1}"
sh """ echo $BUILD
docker-compose down
docker-compose up -d
ab -n 100 -c 10 -r http://127.0.0.1:50000/ > project.txt
curl -F file=@project.txt -F channels=CLBKQPFB5 -F token=${env.SLACK_TOKEN} https://slack.com/api/files.upload
"""
}
slackSend (color: '#FF0000', message: "FAILED - RECOVERY PREV. BUILD : Job '${env.JOB_NAME} [${env.BUILD_NUMBER.toInteger() - 1}]' (${env.BUILD_URL})")
}
}
}