-
Notifications
You must be signed in to change notification settings - Fork 3
/
Jenkinsfile
110 lines (107 loc) · 3.64 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env groovy
pipeline {
environment {
BUILD_USER = ''
micoAdminRegistry = "ustmico/mico-admin"
micoCoreRegistry = "ustmico/mico-core"
registryCredential = 'dockerhub'
micoAdminDockerImage = ''
micoCoreDockerImage = ''
}
agent any
stages {
stage('Checkout') {
steps {
git url: 'https://github.com/UST-MICO/mico.git'
}
}
stage('Docker build') {
parallel {
stage('mico-core') {
steps {
script {
micoCoreDockerImage = docker.build(micoCoreRegistry, "-f Dockerfile.mico-core .")
}
}
}
stage('mico-admin') {
steps {
script {
micoAdminDockerImage = docker.build(micoAdminRegistry, "-f Dockerfile.mico-admin .")
}
}
}
}
}
stage('Unit tests') {
steps {
script {
docker.build(micoCoreRegistry + ":unit-tests", "-f Dockerfile.mico-core.unittests .")
}
sh '''docker run ${micoCoreRegistry}:unit-tests'''
}
}
stage('Integration tests') {
steps {
script {
docker.build(micoCoreRegistry + ":integration-tests", "-f Dockerfile.mico-core.integrationtests .")
}
sh '''docker run ${micoCoreRegistry}:integration-tests'''
}
}
stage('Push images') {
steps {
script{
docker.withRegistry('', 'dockerhub') {
micoCoreDockerImage.push("kube$BUILD_NUMBER")
micoAdminDockerImage.push("kube$BUILD_NUMBER")
micoCoreDockerImage.push("latest")
micoAdminDockerImage.push("latest")
}
}
}
}
stage('Deploy on Kubernetes') {
parallel {
stage('mico-core') {
steps{
sh '''IMAGE_NAME="ustmico/mico-core:kube${BUILD_NUMBER}"
kubectl set image deployment/mico-core mico-core=$IMAGE_NAME -n mico-system --kubeconfig /var/lib/jenkins/config'''
}
}
stage('mico-admin') {
steps{
sh '''IMAGE_NAME="ustmico/mico-admin:kube${BUILD_NUMBER}"
kubectl set image deployment/mico-admin mico-admin=$IMAGE_NAME -n mico-system --kubeconfig /var/lib/jenkins/config'''
}
}
}
}
stage('Docker clean up') {
steps {
// Delete all images that are older than 10 days
sh '''docker system prune --all --force --filter "until=240h"'''
}
}
}
post {
success {
notification('SUCCESS')
}
failure {
notification('FAILURE')
}
always {
// Clean workspace
cleanWs()
}
}
}
def notification(String result) {
COLOR_MAP = ['SUCCESS': 'good', 'FAILURE': 'danger', 'UNSTABLE': 'danger', 'ABORTED': 'danger']
wrap([$class: 'BuildUser']) {
slackSend channel: '#ci-pipeline',
color: COLOR_MAP[result],
message: "*${result}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} by ${env.BUILD_USER}\n More info at: ${env.BUILD_URL}"
}
}