-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
88 lines (86 loc) · 3.44 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
pipeline {
agent {
docker { image 'golang:1.18-stretch' }
}
environment {
GO114MODULE = 'on'
CGO_ENABLED = 0
GOPATH = "/go"
HOME = "/home/perolo/Jenkins/workspace/${JOB_NAME}"
}
stages {
stage('Pre Test') {
steps {
echo 'Installing dependencies'
sh 'env'
sh 'pwd'
sh 'go version'
sh 'go install honnef.co/go/tools/cmd/staticcheck@latest'
sh 'go install github.com/jstemmer/go-junit-report@latest'
sh 'go install github.com/axw/gocov/gocov@latest'
sh 'go install github.com/AlekSi/gocov-xml@latest'
sh 'go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest'
}
}
stage('Build') {
steps {
echo 'Compiling and building'
sh 'go build'
}
}
stage('Test') {
steps {
withEnv(["PATH+GO=${GOPATH}/bin"]){
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE', message: 'Static codecheck errors!') {
echo 'Running vetting'
sh 'go vet .'
echo 'Running staticcheck'
sh 'staticcheck ./...'
echo 'Running golangci-lint'
sh 'golangci-lint run --out-format junit-xml --config .golangci.yml > golangci-lint.xml'
}
echo 'Running test'
sh 'go test -v 2>&1 | go-junit-report > report.xml'
echo 'Running coverage'
sh 'gocov test ./... | gocov-xml > coverage.xml'
}
}
}
stage('Artifacts') {
steps {
script {
if (fileExists('report.xml')) {
archiveArtifacts artifacts: 'report.xml', fingerprint: true
try {
junit 'report.xml'
} catch (err) {
echo err.getMessage()
echo "Error detected, but we will continue."
echo "No lint errors found is not an error."
}
}
if (fileExists('coverage.xml')) {
try {
archiveArtifacts artifacts: 'coverage.xml', fingerprint: true
cobertura coberturaReportFile: 'coverage.xml'
} catch (err) {
echo err.getMessage()
echo "Error detected, but we will continue."
echo "No lint errors found is not an error."
}
}
if (fileExists('golangci-lint.xml')) {
archiveArtifacts artifacts: 'golangci-lint.xml'
try {
junit 'golangci-lint.xml'
} catch (err) {
echo err.getMessage()
echo "Error detected, but we will continue."
echo "No lint errors found is not an error."
}
}
}
}
}
}
}