-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile
57 lines (48 loc) · 1.89 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
def setCoverageBadge(goPath) {
def coverage = sh(script: "cd ${goPath} && cat coveragepct", returnStdout: true)
def coverageUri = "\'http://badges.awsp.eltoro.com?project=drygopher&item=coverage&value=${coverage}&color=yellow\'"
sh "curl -sX POST ${coverageUri}"
}
def setBuildStatusBadge(status, color) {
def statusUri = "\'http://badges.awsp.eltoro.com?project=drygopher&item=build&value=${status}&color=${color}\'"
sh "curl -sX POST ${statusUri}"
}
def slackSuccess() {
def slack_message = "drygopher build succeeded!"
slackSend channel: '#dev-badass-badgers', message: "${slack_message}", failOnError:true, tokenCredentialId: 'slack-token', color:"danger"
}
def slackFailure(){
def slack_message = "drygopher build failed! Details: ${BUILD_URL}"
slackSend channel: '#dev-badass-badgers', message: "${slack_message}", failOnError:true, tokenCredentialId: 'slack-token', color:"good"
}
node {
String goPath = "/go/src/github.com/eltorocorp/drygopher"
docker.image("golang:1.13").inside("-v ${pwd()}:${goPath} -u root") {
try {
stage('Pre-Build') {
setBuildStatusBadge('pending', 'blue')
sh "chmod -R 0777 ${goPath}"
checkout scm
sh "cd ${goPath} && make prebuild"
}
stage('Build') {
sh "cd ${goPath} && make build"
}
stage('Test') {
sh "cd ${goPath} && make test"
}
stage("Post-Build") {
setBuildStatusBadge('passing', 'green')
slackSuccess()
currentBuild.result = 'SUCCESS'
}
} catch (Exception err) {
sh "echo ${err}"
slackFailure()
setBuildStatusBadge('failing', 'red')
currentBuild.result = 'FAILURE'
} finally {
setCoverageBadge(goPath)
}
}
}