-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
57 lines (56 loc) · 1.99 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
#!/usr/bin/env groovy
pipeline {
agent any
tools {
go "golang"
}
environment {
GOPATH = "${env.WORKSPACE}/../go"
PATH = "${PATH}:${GOPATH}/bin"
}
options {
buildDiscarder(logRotator(daysToKeepStr: '90', artifactNumToKeepStr: '3'))
}
stages {
stage('Preflight') {
steps {
echo sh(returnStdout: true, script: 'env')
sh 'git log --reverse -1'
}
}
stage('Init') {
steps {
sh 'rm -f go.sum'
sh 'go get -u golang.org/x/tools/cmd/cover@latest'
sh 'go get -u golang.org/x/tools/cmd/stringer@latest'
sh 'go get -u github.com/t-yuki/gocover-cobertura@latest'
sh 'go get -u github.com/jstemmer/go-junit-report@latest'
sh 'stringer -type=DeviceType,BrowserName,OSName,Platform -output=vars/const_string.go vars/const.go'
sh 'gofmt -s -w .'
}
}
stage('Test') {
steps {
// Test with benchmark and coverage report
sh 'go test -v ./... -bench=. -coverpkg=./... -coverprofile=coverage.txt.tmp -covermode=atomic 2>&1 | go-junit-report > test_results.xml'
// remove auto-generated file of "go stringer" from coverage report
sh 'cat coverage.txt.tmp | grep -v "vars/const_string.go" > coverage.txt'
//
sh 'gocover-cobertura < coverage.txt > coverage.xml'
}
}
}
post {
always {
junit 'test_results.xml'
cobertura coberturaReportFile: 'coverage.xml'
emailext subject: '$DEFAULT_SUBJECT',
body: '''${SCRIPT, template="report.template"}''',
from: 'jenkins@redeviation.com',
to: '$DEFAULT_RECIPIENTS'
}
// cleanup {
// cleanWs()
// }
}
}