-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathJenkinsfile
71 lines (62 loc) · 1.94 KB
/
Jenkinsfile
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
pipeline {
agent any
triggers {
pollSCM('')
}
stages {
stage('Install') {
steps {
sh 'echo "installing the required dependencies in requirements.txt using pip"'
sh 'pip install -r requirements.txt --user'
}
}
stage('Test') {
steps {
sh 'echo "executing tests using pytest"'
sh 'python -m pytest --html=reports/flask-test-report.html --self-contained-html test_app.py'
}
}
stage('Build') {
steps {
sh 'echo "building the repo"'
echo "Running ${env.BUILD_ID} on ${env.JENKINS_URL}"
sh "docker build -t flaskapp:${env.BUILD_ID} ."
sh "docker images"
}
}
stage('Docker Delete Container') {
steps {
echo 'Delete existing container if any'
sh 'docker ps -qa --filter "name=flaskdemo" | xargs -r docker rm -f'
}
}
stage('Deploy') {
steps {
echo 'Deploying the flask application'
sh "docker run -itd -p 8070:5000 --name=flaskdemo flaskapp:${env.BUILD_ID}"
sh 'docker ps -a'
}
}
}
post {
always {
echo 'The pipeline completed, publishing results as report'
// publish html
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'reports',
reportFiles: 'flask-test-report.html',
reportName: 'Flask Test Results'
]
}
success {
echo 'Flask Application Up and running!!'
}
failure {
echo 'Build stage failed'
error('Stopping early…')
}
}
}