This repository has been archived by the owner on Aug 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
62 lines (59 loc) · 2.08 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
pipeline {
agent any
environment {
scannerHome = tool 'SonarQube'
SONARQUBE_TOKEN = credentials('SONARQUBE_TOKEN')
DOCKER_HUB_PASSWORD = credentials('DOCKER_HUB_PASSWORD')
}
stages {
stage('Clear running apps') {
steps {
sh 'docker rm -f devops_flask_app || true'
}
}
stage('Sonarqube analysis frontend') {
steps {
withSonarQubeEnv('SonarQube') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.login=${SONARQUBE_TOKEN}"
}
timeout(time: 1, unit: 'MINUTES') {
waitForQualityGate abortPipeline: true
}
}
}
stage('Build Docker Image') {
steps {
sh "docker build -t devops_flask_app:${BUILD_NUMBER} -t devops_flask_app:latest ."
}
}
stage('Run app') {
steps {
sh "docker run -d -p 0.0.0.0:5555:5555 --net=devops-environment_docker_network --name devops_flask_app -t devops_flask_app:${BUILD_NUMBER}"
}
}
stage('Selenium tests') {
steps {
dir('tests/') {
sh 'pip3 install -r requirements.txt'
sh 'python3 test_app.py'
}
}
}
stage('Upload Docker Image to Docker Hub') {
steps {
sh "docker login -u dodgo -p ${DOCKER_HUB_PASSWORD}"
sh "docker tag devops_flask_app:${BUILD_NUMBER} dodgo/devops_flask_app:${BUILD_NUMBER}"
sh 'docker tag devops_flask_app:latest dodgo/devops_flask_app:latest'
sh "docker push dodgo/devops_flask_app:${BUILD_NUMBER}"
sh 'docker push dodgo/devops_flask_app:latest'
}
}
stage('Cleanup'){
steps{
sh 'docker kill devops_flask_app'
sh 'docker rm devops_flask_app'
sh 'docker image rm dodgo/devops_flask_app:${BUILD_NUMBER}'
}
}
}
}