From 17867421ebcf42779f7afd6811134b8a33a80d8c Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Mon, 26 Sep 2022 18:27:02 +0200 Subject: [PATCH] Add Linting and tests to Jenkins pipeline --- Jenkinsfile | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7625ae2..13c8c74 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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' }