-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
79 lines (70 loc) · 1.86 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
73
74
75
76
77
78
79
pipeline {
agent any
stages {
stage('Build Project') {
steps {
sh 'mvn clean install'
}
}
stage('Static Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh 'mvn clean verify sonar:sonar -Dsonar.projectKey=decklearn'
}
}
}
stage('Quality Gate') {
steps {
timeout(time: 10, unit: 'SECONDS') {
waitForQualityGate true
}
}
}
stage('Unit Test') {
steps {
sh 'mvn clean test'
}
}
stage('Remove docker container and image') {
when {
branch 'develop'
}
steps {
sh 'docker ps -f name=decklearn -q | xargs --no-run-if-empty docker container stop'
sh 'docker container ls -a -fname=decklearn -q | xargs -r docker container rm'
sh 'docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi'
}
}
stage('Create docker image') {
when {
branch 'develop'
}
steps {
withCredentials(bindings: [usernamePassword(credentialsId: 'dockerhub-credentials', passwordVariable: 'pass', usernameVariable: 'name')]) {
sh 'mvn compile jib:dockerBuild -Djib.to.auth.username=$name -Djib.to.auth.password=$pass'
}
}
}
stage('Run decklearn container') {
when {
branch 'develop'
}
steps {
sh 'docker run -d -p 8080:8080 --name decklearn alejandrocalleja/decklearn'
}
}
stage('Publish docker image') {
when {
branch 'release'
}
steps {
withCredentials(bindings: [usernamePassword(credentialsId: 'dockerhub-credentials', passwordVariable: 'pass', usernameVariable: 'name')]) {
sh 'mvn compile jib:build -Djib.to.auth.username=$name -Djib.to.auth.password=$pass'
}
}
}
}
tools {
maven 'maven'
}
}