-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
120 lines (119 loc) · 3.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
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
111
112
113
114
115
116
117
118
119
120
import groovy.json.JsonOutput
pipeline {
agent any
environment {
GIT_COMMIT = sh (script: "git log -n 1 --pretty=format:'%h' --abbrev=7", returnStdout: true)
}
stages {
stage('Test') {
agent{
docker{
image 'python:3.8'
reuseNode true
args '-u root:root'
}
}
steps {
script {
sh 'pip install --user -r requirements/test.txt'
sh 'python -m unittest discover -s ./test --pattern \'*.py\' '
}
}
}
stage('Building image') {
steps{
script {
dockerImage = docker.build("dsp/eland-preprocessing:${env.BUILD_NUMBER}_${GIT_COMMIT}")
}
}
}
stage('Deploy Image') {
steps{
script {
docker.withRegistry('http://dockerhub.vpon.com') {
dockerImage.push("${env.BUILD_NUMBER}_${GIT_COMMIT}")
dockerImage.push('latest')
}
}
}
}
}
post {
success {
script {
def data = [
attachments:[
[
"color" : "#36a64f",
"title" : "Jenkins-Test-Result",
"title_link" : "$env.BUILD_URL",
"fields" :[
[
"title": "JobName",
"value": "$env.JOB_NAME",
],,
[
"title": "BranchName",
"value": "$env.BRANCH_NAME",
],
[
"title": "CommitHash",
"value": "$GIT_COMMIT",
],
[
"title": "BuildNumber",
"value": "$BUILD_NUMBER",
],
[
"title": "ImageName",
"value": "dsp/eland-preprocessing:${env.BUILD_NUMBER}_${GIT_COMMIT}",
]
]
]
]
]
def json = JsonOutput.toJson(data)
slackSend(json)
}
}
failure {
script {
def data = [
attachments:[
[
"color" : "#FF0000",
"title" : "Jenkins-Test-Result",
"title_link" : "$env.BUILD_URL",
"fields" :[
[
"title": "JobName",
"value": "$env.JOB_NAME",
],,
[
"title": "BranchName",
"value": "$env.BRANCH_NAME",
],
[
"title": "CommitHash",
"value": "$GIT_COMMIT",
],
[
"title": "BuildNumber",
"value": "$BUILD_NUMBER",
]
]
]
]
]
def message = JsonOutput.toJson(data)
slackSend(message.toString())
}
}
}
}
def slackSend(message){
def s ='''
curl -X POST -H \'Content-type: application/json\' --data \'%s\' https://hooks.slack.com/services/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
'''
sh String.format(s,message)
}