简体   繁体   English

TeamCity:成功构建推送到Git Repo

[英]TeamCity: On successful build push to Git Repo

Can TeamCity push successful builds to a git repository? TeamCity可以将成功的构建推送到git存储库吗?

I cannot see a specific build step in TeamCity to do this. 我无法在TeamCity中看到特定的构建步骤来执行此操作。
I use the version 7.1.1 of 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. 我发现我可以简单地将成功构建的标签推回到我的全局存储库,TeamCity从该存储库获取构建数据。 I can pull changes from it and see whether the last commits were successful. 我可以从中提取更改并查看上次提交是否成功。

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? 如果每个开发人员都可以从仅在构建成功时更新的repo中提取,或者我在这里错了,那将是非常棒的吗?

You can have TeamCity execute a shell script that subsequently calls git push (with appropriate arguments, eg git push <repository> to push to a different repository). 您可以让TeamCity执行一个shell脚本,随后调用git push (使用适当的参数,例如git push <repository>来推送到另一个存储库)。 Do make sure that git doesn't need interactive authentication for the push operation. 确保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部署到Heroku): http//blog.carbonfive.com/2010/08/06/deploying-to-heroku-from-teamcity/

If you upgrade to 8 or newer you can just make one or more "Automatic Merge" build features. 如果升级到8或更高版本,则可以创建一个或多个“自动合并”构建功能。 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. 我最初没有找到它,或者是因为令人困惑的命名,但是它们必须支持具有不同命名的许多不同VCS才有意义。

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 亨里克

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). 防止这种情况的一种方法是每次项目构建时都要求创建/运行+2测试(可在TeamCity中配置)。 These caveats are mentioned in the previously linked article announcing the Automatic Merge feature. 这些警告在之前链接的文章中提到,它宣布了自动合并功能。

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: 我们最终做的是:

  1. 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. 使用“环境变量”类型的参数(构建代理可见,其他类型不可用)并设置“规范”以生成“密码”类型的字段,这将阻止输入的文本显示在配置中UI或作业日志输出。
  2. Entered the username and password as parameters on the job config 在作业配置中输入用户名和密码作为参数
  3. 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:gitpassword@githost.com/path/to/repo.git ) in order to push the changes on a new branch. 创建了一个脚本,该脚本查看了“代理端”存储库的git远程URL,并在URL中添加了一个内联用户名和密码的新远程控制器http:// gituser:gitpassword@githost.com/path/to/repo。 git )以推动新分支的更改。
    • 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. 当然,凭证也是相当严格的范围,只能访问某些存储库,但最小权限规则总是很好。

My solution maybe is stupid, but simple. 我的解决方案可能是愚蠢的,但很简单。 The steps is as follows: 步骤如下:

  1. Cloning your heroku from heroku git repository it will create your heroku app folder. 从heroku git存储库克隆你的heroku它将创建你的heroku app文件夹。

    heroku git:clone -a {app-name}

  2. Copy the files you need to update to heroku 将需要更新的文件复制到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

  3. git add. git add。

    cd {app-name} && git add .

  4. git commit git commit

    cd {app-name} && git commit --message 'ok'

  5. push to heroku 推到heroku

    cd {app-name} && git push heroku master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM