forked from Kelvinskell/microservices-devops-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
72 lines (65 loc) · 2.35 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
72
pipeline {
agent any
stages{
stage('SCA with OWASP Dependency Check') {
steps {
dependencyCheck additionalArguments: '''--format HTML
''', odcInstallation: 'DP-Check'
}
}
stage('SonarQube Analysis') {
steps {
script {
// requires SonarQube Scanner 2.8+
scannerHome = tool 'SonarScanner'
}
withSonarQubeEnv('Sonarqube Server') {
sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=newsread-microservice-application"
}
}
}
stage('Build Docker Images') {
steps {
script{
sh 'docker build -t kelvinskell/newsread-customize customize-service/'
sh 'docker build -t kelvinskell/newsread-news news-service/'
}
}
}
stage('Containerize And Test') {
steps {
script{
sh 'docker run -d --name customize-service -e FLASK_APP=run.py kelvinskell/newsread-customize && sleep 10 && docker logs customize-service && docker stop customize-service'
sh 'docker run -d --name news-service -e FLASK_APP=run.py kelvinskell/newsread-news && sleep 10 && docker logs news-service && docker stop news-service'
}
}
}
stage('Push Images To Dockerhub') {
steps {
script{
withCredentials([string(credentialsId: 'DockerHubPass', variable: 'DockerHubPass')]) {
sh 'docker login -u kelvinskell --password ${DockerHubPass}' }
sh 'docker push kelvinskell/newsread-news && docker push kelvinskell/newsread-customize'
}
}
}
//stage('Trivy scan on Docker images'){
// steps{
// sh 'TMPDIR=/home/jenkins'
// sh 'trivy image kelvinskell/newsread-news:latest'
// sh 'trivy image kelvinskell/newsread-customize:latest'
//}
// }
}
post {
always {
// Always executed
sh 'docker rm news-service'
sh 'docker rm customize-service'
}
success {
// on sucessful execution
sh 'docker logout'
}
}
}