1.9 KiB
1.9 KiB
Exercise 13
We'll want to enhance the pipeline by additional stages and implement a release workflow. The project is going to use an external tool called GoReleaser to publish cross-compiled artifacts to GitHub Releases. The binaries should only be released if the commit has been tagged.
Enhancing a Pipeline With Advanced Features
- Add stage named
Testthat executes the Gotestcommand.- Add a build step that runs the shell command
go test ./.... - Generate code coverage metrics by adding the option
-coverprofile=coverage.txtto the build step. - Publish the code coverage metrics to CodeCov by sending a curl command
curl -s https://codecov.io/bash | bash -s -. - Log into CodeCov, determine the CodeCov token for the repository (aka Repository Upload Token) and set it up as credential in Jenkins.
- Retrieve the credential and set the value as environment variable named
CODECOV_TOKEN.
- Add a build step that runs the shell command
- Add a stage named
Code Analysisthat uses golangci-lint to detect issues with the code.- Add a build step for installing the
golangci-lintwith the shell commandcurl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.17.1 - Add a build step that runs
golangci-lintwith the shell commandgolangci-lint run.
- Add a build step for installing the
- Add a stage named
Releasethat uses GoReleaser.- Only build this step if the commit has been tagged.
- Set up a credential in Jenkins named
github_tokenand set your GitHub token. - Retrieve the credential and set the value as environment variable named
GITHUB_TOKEN. - Add a build step that runs the shell command
curl -sL https://git.io/goreleaser | bash.