英文:
Recommended Go build system for a CI server?
问题
所以我有一个使用go-gettable依赖项和测试等的Go项目。
我想将其集成到Jenkins中。除了编写makefile之外,有没有其他人推荐的用于此用例的自动构建系统?
我需要:
- 自动安装go-get依赖项(它们当然可以在规范文件中)
- 递归构建。
- 运行测试。
- GOPATH/GOROOT管理(用于隔离SDK和路径)
我以前使用过godag来完成这种工作,但它似乎有点不维护了。
编辑:目前,我使用以下脚本直接输入到Jenkins作为构建步骤:
#这个命令获取依赖项但不安装它们,避免权限问题
go get -d
#构建包,-x输出编译器命令行
go build -x
#这个有点棘手 - ./... 表示“对于每个子包递归执行”
go test ./...
英文:
So I have a go project with go-gettable dependencies, tests, etc.
I want to integrate it into Jenkins. Is there an automated build system for go that anyone recommends for this use case, other than writing makefiles?
I need:
- <s>automatic installation of go-get deps (they can be in a spec file of course)</s>
- recursive build.
- running tests.
- GOPATH/GOROOT management (to isolate SDKs and paths)
I've used godag in the past for this sort of job but it seems a bit unmaintained.
EDIT: For the time being I'm living with the following script entered directly into Jenkins as a build step:
#this gets the dependencies but doesn't install them, avoiding permission problems
go get -d
#build the packages, -x outputs the compiler command line
go build -x
#this was tricky - ./... means "for each sub-package recursively"
go test ./...
答案1
得分: 8
你也可以使用TeamCity来完成这个任务。
以下是一个构建Terraform的示例。
TeamCity代理设置:
- 安装Go
- 将Go添加到环境变量中
- 不要忘记重新启动代理,因为路径已更改
TeamCity构建设置:
-
使用代理端检出(如果我们想要包括.git文件夹,因为很多构建脚本都会使用它)
-
使用检出规则(我们想要使用Go的约定):
+:. => src/github.com/mitchellh/terraform
构建步骤:
echo cd %system.teamcity.build.checkoutDir%
cd "%system.teamcity.build.checkoutDir%"
path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
echo path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
set GOPATH=%system.teamcity.build.checkoutDir%
echo set GOPATH=%system.teamcity.build.checkoutDir%
echo "获取依赖项"
go get golang.org/x/tools/cmd/vet
go get golang.org/x/tools/cmd/cover
go get golang.org/x/tools/cmd/stringer
go get github.com/mitchellh/gox
echo cd %system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform
cd "%system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform"
echo "更新资源"
go get ./...
echo "运行静态代码分析"
go tool vet -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr .
echo "构建"
cd scripts
sh build.sh
echo "运行单元测试"
go test -timeout=30s -parallel=4
echo "运行代码覆盖率"
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
rm coverage.out
英文:
You can do it with teamcity as well.
Here is an example for building terraform.
Teamcity agent setup:
- Install Go
- Add Go to path
- Don't forget to restart agent as path was changed
Teamcity build setup:
-
Use agent side checkout (if we want to include the .git folder, which a lot of build scripts make use of)
-
Use checkout rule (we want to use the Go convention):
+:. => src/github.com/mitchellh/terraform
Build steps:
echo cd %system.teamcity.build.checkoutDir%
cd "%system.teamcity.build.checkoutDir%"
path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
echo path=C:\Program Files (x86)\Git\bin;%env.Path%;%system.teamcity.build.checkoutDir%\bin;
set GOPATH=%system.teamcity.build.checkoutDir%
echo set GOPATH=%system.teamcity.build.checkoutDir%
echo "Getting dependancies"
go get golang.org/x/tools/cmd/vet
go get golang.org/x/tools/cmd/cover
go get golang.org/x/tools/cmd/stringer
go get github.com/mitchellh/gox
echo cd %system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform
cd "%system.teamcity.build.checkoutDir%\src\github.com\mitchellh\terraform"
echo "Update resources"
go get ./...
echo "Run static code analysis"
go tool vet -asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr .
echo "Build"
cd scripts
sh build.sh
echo "Run unit tests"
go test -timeout=30s -parallel=4
echo "Run code coverage"
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
rm coverage.out
答案2
得分: 2
我正在使用在Mac上运行的Team City构建服务器,它运行一个rake文件,在rake文件中,我执行所有的命令来获取依赖项(go gets),运行测试并构建到正确的环境。
如果你需要在编写Rake文件方面的指导,请告诉我。
另外,我一直在使用这个框架为REST API创建功能测试。这个框架已经多次帮助我节省了代码。你可以在http://github.com/DigitalInnovation/cucumber_rest_api找到它。
英文:
I am using a Team City build server on a Mac that runs a rake file, in the rake file I do all the commands to get dependancies, (go gets), tests and builds to the correct environment.
let me know if you want any pointers in writing the Rake files,
As a side note, i have been creating functional tests for REST Api's using this frame work. This has saved my code many times over. http://github.com/DigitalInnovation/cucumber_rest_api
答案3
得分: 0
自2019年8月起,TeamCity 2019.1现在直接支持Go语言。请参阅“在TeamCity中构建Go程序”。
要在TeamCity中启用Go支持,您需要:
- 进入“构建配置设置”|“构建特性”页面,
- 点击“添加构建特性”,
- 从列表中选择“Golang”。
TeamCity内置支持Go语言,无需安装外部插件。TeamCity解析go test命令的执行结果,并将结果持久化存储,可以从历史角度查看这些数据。因此,所有与测试报告相关的TeamCity功能现在都适用于Go开发人员。
英文:
Since August 2019, TeamCity 2019.1 now supports Go directly.
See "Building Go programs in TeamCity"
> To enable Go support in TeamCity,
> - go to Build Configuration Settings
| Build Features
,
- click
Add build feature
, and - select
Golang
from the list.
> Support for Go is provided by TeamCity out of the box, there are no external plugins required.
TeamCity parses results of go test command execution. The results are persisted and it is possible to review the figures in a historical perspective.
Consequently, all the TeamCity features that are related to test reporting are now available for Go developers.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论