-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
82 lines (77 loc) · 1.87 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
80
81
82
pipeline {
agent any
stages {
stage('Build JAR') {
steps {
sh '''mvn clean install
echo \'hello\''''
}
}
stage('Code Coverage') {
steps {
jacoco(changeBuildStatus: true, execPattern: 'backend/target/jacoco.exec', classPattern: 'backend/target/classes', sourcePattern: 'backend/src/main/java', exclusionPattern: 'backend/test*', deltaLineCoverage: '0', deltaMethodCoverage: '0', maximumLineCoverage: '0')
}
}
stage('Static code analysis') {
environment {
scannerHome = tool 'sonar_scanner'
}
steps {
withSonarQubeEnv('Sonar_server') {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
stage('Build Docker Image') {
steps {
script {
dockerImage = docker.build registry + ":$BUILD_NUMBER"
}
}
}
stage('Push Image To DockerHub') {
steps {
script {
docker.withRegistry('', registryCredential) {
dockerImage.push()
dockerImage.push('latest')
}
}
}
}
stage('Clean up Workspace'){
steps {
cleanWs()
}
}
stage('Remove Unused Docker Image') {
steps {
sh "docker rmi $registry:$BUILD_NUMBER"
sh "docker rmi $registry:latest"
}
}
stage('Approve deployment') {
when {
branch 'master'
}
steps {
input 'Deploy on K8s?'
}
}
stage('Deploy on K8s') {
when {
branch 'master'
}
steps {
withKubeConfig(credentialsId: 'k8scli', serverUrl: 'https://35.204.194.137') {
sh 'kubectl set image deployment/ride2work ride2work=ride2work/ride2work:$BUILD_NUMBER'
}
}
}
}
environment {
registry = 'ride2work/ride2work'
registryCredential = 'dockerhub'
dockerImage = ''
}
}