Clarify some details

This commit is contained in:
Benjamin Muschko
2019-11-18 17:11:32 -07:00
parent 248499c8f6
commit 57896f0303
17 changed files with 82 additions and 40 deletions

View File

@@ -1,16 +1,9 @@
# Solution
Create the credentials for the CodeCov token.
![CodeCov Credentials](./images/codecov_token_credentials.png)
You can implement the "Test" stage as follows.
```groovy
stage('Test') {
environment {
CODECOV_TOKEN = credentials('CODECOV_TOKEN')
}
steps {
sh 'go test ./... -coverprofile=coverage.txt'
sh "curl -s https://codecov.io/bash | bash -s -"
@@ -23,7 +16,7 @@ You can implement the "Code Analysis" stage as follows.
```groovy
stage('Code Analysis') {
steps {
sh 'curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.17.1'
sh 'curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.18.0'
sh 'golangci-lint run'
}
}
@@ -47,4 +40,48 @@ stage('Release') {
sh 'curl -sL https://git.io/goreleaser | bash'
}
}
```
The final `Jenkinsfile` looks similar to the solution below.
```groovy
pipeline {
agent any
tools {
go 'go-1.12'
}
environment {
GO111MODULE = 'on'
}
stages {
stage('Build') {
steps {
sh 'go build'
}
}
stage('Test') {
steps {
sh 'go test ./... -coverprofile=coverage.txt'
sh "curl -s https://codecov.io/bash | bash -s -"
}
}
stage('Code Analysis') {
steps {
sh 'curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.18.0'
sh 'golangci-lint run'
}
}
stage('Release') {
when {
buildingTag()
}
environment {
GITHUB_TOKEN = credentials('GITHUB_TOKEN')
}
steps {
sh 'curl -sL https://git.io/goreleaser | bash'
}
}
}
}
```