Mercurial 基于推送构建
我希望每次推送到我们的中央 Mercurial 存储库时都(在服务器上)完成构建。 构建通常是通过手动或通过计划任务运行可视化构建文件在我们的构建服务器上启动的。
有哪些方法可以实现这一目标?
简单、低影响的解决方案是首选。
I'd like for a build to be done (on the server) each time a push is made to our central Mercurial repository.
Builds are usually kicked off on our build server by running a Visual Build file either manually or via a scheduled task.
What are the ways of achieving this?
Simple, low impact solutions are preferred.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Pablo 建议的那样,您可以使用钩子来完成此操作,但您需要在服务器端有一个传入钩子。此挂钩在“将变更集拉取、推送或解绑到本地存储库后”运行(hgrc 联机帮助页)。
编辑位于服务器上的存储库的
.hg/hgrc
文件,并按如下方式定义构建挂钩:当然,此处调用的构建脚本只需成为您实际使用的任何构建过程的触发器。
请注意,传入 挂钩会针对推送中的每个变更集运行。如果您不想这样做,请使用 changegroup 挂钩 - 每次推送它只运行一次,无论它携带多少个变更集。
As Pablo suggested, you can do this with a hook, but you'll need an incoming hook on the server side. This hook runs "after a changeset has been pulled, pushed, or unbundled into the local repository" (hgrc manpage).
Edit the
.hg/hgrc
file of the repository located on the server and define your build hook as follows:Of course, the build script called here just needs to be a trigger for whatever build process you actually use.
Note that an incoming hook runs for every single changeset in a push. If you don't want this, use a changegroup hook -- it runs only once for each push, no matter how many changesets it carries.
除了 Pablo 提到的钩子之外,另一种方法是设置持续集成服务器,例如 TeamCity。然后,您可以要求 TeamCity 监视您的存储库、提取新的变更集并为您启动可视化构建脚本。
Another way, in addition to the hooks that Pablo mentions, is to set up a continuous integration server, like TeamCity. Then you could ask TeamCity to monitor your repository, pull new changesets and start the visual build script for you.
免责声明
这些发现适用于 win32 上 apache 后面的 tortoisehg 客户端和 Mercurial 服务器。
尝试 #1
最简单的解决方案是让您的推送启动构建。
在
.hg\hgrc
中build.py
问题
你会发现,在推送之后,在 os.system 调用返回之前,tortoise hg 客户端不会返回。这可能会也可能不会被接受。在我的店里,一个构建花了大约 20 分钟,我的老板认为这是不可接受的。
尝试#2
我的解决方案是在根目录中创建 REQUESTBUILD 文件后,挂钩立即返回。
在
.hg\hgrc
在
.hg\write_buildrequest_file.bat
同时,我有一个在无限循环中运行的 python 脚本,检查 REQUESTBUILD 是否存在。
在
.hg\monitor_buildrequest_file.py
中,build.py
将生成结果的 HTML 文件,提交者必须通过其 Web 浏览器提取该文件。还有其他问题(在构建开始时推送、保存历史结果、在工作目录之外构建与在其他地方复制),但这是总体思路。
Disclaimer
These findings are for tortoisehg client and mercurial server behind apache on win32.
Try #1
The naive solution would be to make your push kick off the build.
In
.hg\hgrc
In
build.py
Problem
What you'll find is that, after a push, the tortoise hg client won't return until your os.system call returns. This may or not be acceptable. In my shop a build took about 20 minutes, and my boss deemed that unacceptable.
Try #2
My solution was for the hook to return immediately after creating a REQUESTBUILD file to the root directory.
In
.hg\hgrc
In
.hg\write_buildrequest_file.bat
Meanwhile, I had a python script running in an infinite loop, checking for the presence of REQUESTBUILD.
In
.hg\monitor_buildrequest_file.py
build.py
would generate an HTML file of results, which the submitter would have to pull via their web browser.There are other issues (pushes while a build is commencing, saving historical results, building out of the working directory vs copying elsewhere) but this is the general idea.
您需要使用钩子处理存储库事件。
因此,在
commit
事件之后,您需要运行一个脚本来相应地执行构建。You need to handle repository events with hooks.
So, after
commit
event you need to run a script that will perform your build accordingly.