TeamCity:成功构建推送到 Git Repo
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13326487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TeamCity: On successful build push to Git Repo
提问by Henrik
Can TeamCity push successful builds to a git repository?
TeamCity 可以将成功的构建推送到 git 存储库吗?
I cannot see a specific build step in TeamCity to do this.
I use the version 7.1.1 of TeamCity
我在 TeamCity 中看不到执行此操作的特定构建步骤。
我使用的是 TeamCity 7.1.1 版本
Thanks, Henrik
谢谢,亨里克
UPDATE:
更新:
Ok thanks for your answer, I find it a bit complicated. I found out that I can simply push back tags on successful builds to my global repository from which TeamCity fetches data for the build. I can pull changes from it and see whether the last commits were successful.
好的,谢谢你的回答,我觉得有点复杂。我发现我可以简单地将成功构建的标签推回我的全局存储库,TeamCity 从中获取构建数据。我可以从中提取更改并查看最后一次提交是否成功。
I would be happy if TeamCity provided a simple option for this kind of workflow!
如果 TeamCity 为这种工作流程提供了一个简单的选项,我会很高兴!
It would be awesome if every developer could just pull from a repo that is only updated when the build is successful, or am I wrong here?
如果每个开发人员都可以从仅在构建成功时更新的存储库中提取,那将会很棒,或者我在这里错了吗?
采纳答案by praseodym
You can have TeamCity execute a shell script that subsequently calls git push
(with appropriate arguments, e.g. git push <repository>
to push to a different repository). Do make sure that git
doesn't need interactive authentication for the push operation.
您可以让 TeamCity 执行随后调用的 shell 脚本git push
(使用适当的参数,例如git push <repository>
推送到不同的存储库)。请确保git
推送操作不需要交互式身份验证。
A related example (deploy to Heroku using a git push
) can be found here: http://blog.carbonfive.com/2010/08/06/deploying-to-heroku-from-teamcity/.
git push
可以在此处找到相关示例(使用 a 部署到 Heroku ):http: //blog.carbonfive.com/2010/08/06/deploying-to-heroku-from-teamcity/。
回答by Esben Skov Pedersen
If you upgrade to 8 or newer you can just make one or more "Automatic Merge" build features. This will push to remote repo. I didn't find it at first either because of the confusing naming but it makes sense that they have to support many different VCS with different naming.
如果您升级到 8 或更高版本,您只需制作一个或多个“自动合并”构建功能。这将推送到远程仓库。起初我也没有发现它,因为命名混乱,但它们必须支持许多具有不同命名的不同 VCS,这是有道理的。
回答by Henrik
i finally made it!
我终于成功了!
You have to add a build parameter in your teamcity project:
您必须在 teamcity 项目中添加构建参数:
name= env.PATH
value= C:\Program Files (x86)\Git\cmd
and then you add a new commandline build step with custom script:
然后使用自定义脚本添加新的命令行构建步骤:
call git push "C:\Gruene Git Repos\TeamCityApp" master
the "call" word is important!
“呼”字很重要!
Thanks for the help! henrik
谢谢您的帮助!亨里克
回答by dragon788
Easy Answer
简单回答
For a while TeamCity has supported VCS Labeling, this allows your VCS Root user (if it has write permissions) to tag the commit hash that was just built with the version or anything else TeamCity knows about (see entire list of parameter references in the TeamCity wiki).
有一段时间 TeamCity 支持 VCS 标签,这允许您的 VCS Root 用户(如果它具有写入权限)标记刚刚使用版本构建的提交哈希或 TeamCity 知道的任何其他内容(请参阅 TeamCity 中参数引用的完整列表维基)。
An aside
一边
As stated in another answer the Automatic Merge functionality available in TeamCity will automatically perform a merge into a requested branch from the specified list of branches (wildcard enabled) and it will monitor and build and only merge them if it succeeds.
正如另一个答案中所述,TeamCity 中可用的自动合并功能将自动从指定的分支列表(启用通配符)中执行合并到请求的分支,并且它将监视和构建并且只有在成功时才合并它们。
The Automatic Merge functionality can be good, but if you don't have good test coverage it can also be dangerous as a developer could break something that doesn't have a test and that will cause issues in your code long down the road. One way to prevent this is to require +2 tests be created/run every time the project builds (configurable in TeamCity). These caveats are mentioned in the previously linked article announcing the Automatic Merge feature.
自动合并功能可能很好,但如果您没有良好的测试覆盖率,它也可能很危险,因为开发人员可能会破坏一些没有测试的东西,这会在很长一段时间内导致您的代码出现问题。防止这种情况的一种方法是要求在每次项目构建时创建/运行 +2 测试(可在 TeamCity 中配置)。这些警告在之前链接的宣布自动合并功能的文章中提到。
Related Resolution
相关决议
We encountered a similar issue not related directly to merging, but having a requirement to push some changes from the job beyond the "lightweight tags" (for Git at least) that TeamCity adds if you use VCS Labeling (terrible name).
我们遇到了一个与合并没有直接关系的类似问题,但是如果您使用 VCS 标签(可怕的名称),我们需要将一些更改从作业中推送到 TeamCity 添加的“轻量级标签”(至少对于 Git)之外。
What we ended up doing was:
我们最终做的是:
- Using a Parameter of the type "Environment Variable" (visible to the build agent, the other types are not) and setting the "Spec" to make the field of type "Password" which will prevent the entered text from showing in either the config UI or the Job log output.
- Entered the username and password as parameters on the job config
- Created a script that looked at the git remote URL of the "agent side" repository and added a new remote with the username and password inline in the url (http://gituser:[email protected]/path/to/repo.git) in order to push the changes on a new branch.
- We then remove the remote at the end of the script so that anyone accessing the system can't pull out the credential. Of course the credential is also fairly tightly scoped to only access certain repositories, but the least privilege rule is always good to follow.
- 使用“环境变量”类型的参数(对构建代理可见,其他类型不可见)并设置“规范”以制作“密码”类型的字段,这将防止输入的文本显示在任一配置中UI 或作业日志输出。
- 在作业配置中输入用户名和密码作为参数
- 创建了一个脚本,该脚本查看“代理端”存储库的 git 远程 URL,并添加了一个新的远程,其用户名和密码内嵌在 url ( http://gituser:[email protected]/path/to/repo.xml ) 中。 git) 以便将更改推送到新分支上。
- 然后我们删除脚本末尾的遥控器,以便任何访问系统的人都无法取出凭证。当然,凭证的范围也相当严格,只能访问某些存储库,但遵循最小特权规则总是好的。
回答by ScottLee
My solution maybe is stupid, but simple. The steps is as follows:
我的解决方案可能很愚蠢,但很简单。步骤如下:
Cloning your heroku from heroku git repository it will create your heroku app folder.
heroku git:clone -a {app-name}
Copy the files you need to update to heroku
xcopy client "{app-name}/client" /e/i/h/y
xcopy server "{app-name}/server" /e/i/h/y
xcopy imports "{app-name}/imports" /e/i/h/y
git add.
cd {app-name} && git add .
git commit
cd {app-name} && git commit --message 'ok'
push to heroku
cd {app-name} && git push heroku master
从 heroku git 存储库克隆您的 heroku 它将创建您的 heroku 应用程序文件夹。
heroku git:clone -a {app-name}
将需要更新的文件复制到heroku
xcopy client "{app-name}/client" /e/i/h/y
xcopy server "{app-name}/server" /e/i/h/y
xcopy imports "{app-name}/imports" /e/i/h/y
git 添加。
cd {app-name} && git add .
提交
cd {app-name} && git commit --message 'ok'
推送到heroku
cd {app-name} && git push heroku master