Add Linting and tests to Jenkins pipeline

This commit is contained in:
Jan Dittberner 2022-09-26 18:27:02 +02:00
parent 57fd5364fc
commit 17867421eb

30
Jenkinsfile vendored
View file

@ -1,6 +1,6 @@
#!groovy
/*
Copyright 2017-2021 Jan Dittberner
Copyright 2017-2022 Jan Dittberner
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this program except in compliance with the License.
@ -21,13 +21,37 @@ pipeline {
go "go-1.18"
}
environment {
GOPATH = "${env.WORKSPACE_TMP}/go"
}
stages {
stage('Build') {
stage('Lint') {
when { not { branch 'debian' } }
steps {
sh "make distclean && make"
script {
if (!fileExists("${env.GOPATH}/bin/golangci-lint")) {
sh label: 'Install golangci-lint', script: 'mkdir -p "$(go env GOPATH)"; curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin'
}
}
sh label: 'Show environment', script: 'go env GOPATH'
sh label: 'Run golangci-lint', script: '$(go env GOPATH)/bin/golangci-lint run --sort-results --verbose --max-same-issues 0 --max-issues-per-linter 0'
}
}
stage('Build') {
when { not { branch 'debian' } }
steps {
sh label: 'Build binary', script: 'make distclean && make'
}
}
stage('Test') {
when { not { branch 'debian' } }
steps {
sh label: 'Run tests', script: 'go test -v ./...'
}
}
stage('Create build output') {
when { not { branch 'debian' } }
steps {
archiveArtifacts artifacts: 'cacert-boardvoting,config.yaml.example'
}