Mercurial 基于推送构建

发布于 2024-10-07 06:30:41 字数 135 浏览 3 评论 0原文

我希望每次推送到我们的中央 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

够运 2024-10-14 06:30:41

正如 Pablo 建议的那样,您可以使用钩子来完成此操作,但您需要在服务器端有一个传入钩子。此挂钩在“将变更集拉取、推送或解绑到本地存储库后”运行(hgrc 联机帮助页)。

编辑位于服务器上的存储库的 .hg/hgrc 文件,并按如下方式定义构建挂钩:

[hooks]
incoming = /path/to/executable-build-script

当然,此处调用的构建脚本只需成为您实际使用的任何构建过程的触发器。

请注意,传入 挂钩会针对推送中的每个变更集运行。如果您不想这样做,请使用 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:

[hooks]
incoming = /path/to/executable-build-script

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.

岛歌少女 2024-10-14 06:30:41

除了 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.

初熏 2024-10-14 06:30:41

免责声明

这些发现适用于 win32 上 apache 后面的 tortoisehg 客户端和 Mercurial 服务器。

尝试 #1

最简单的解决方案是让您的推送启动构建。

.hg\hgrc

[hooks]
incoming=.hg\build.py

build.py

os.system('\Progra~2\Micros~2.0\Common7\IDE\devenv /build release project.sln > logfile')

问题

你会发现,在推送之后,在 os.system 调用返回之前,tortoise hg 客户端不会返回。这可能会也可能不会被接受。在我的店里,一个构建花了大约 20 分钟,我的老板认为这是不可接受的。

尝试#2

我的解决方案是在根目录中创建 REQUESTBUILD 文件后,挂钩立即返回。

.hg\hgrc

[hooks]
incoming = .hg\write_buildrequest_file.bat

.hg\write_buildrequest_file.bat

echo REQUESTBUILD > \REQUESTBUILD

同时,我有一个在无限循环中运行的 python 脚本,检查 REQUESTBUILD 是否存在。

.hg\monitor_buildrequest_file.py 中,

import popen2, time, os
import subprocess

while True:
    if os.path.exists("\REQUESTBUILD"):
        os.system("del \REQUESTBUILD")
        os.chdir("/yourrepo/.hg")
        retcode = subprocess.call("\python27\python.exe build.py")
    else:
        time.sleep(10)

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

[hooks]
incoming=.hg\build.py

In build.py

os.system('\Progra~2\Micros~2.0\Common7\IDE\devenv /build release project.sln > logfile')

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

[hooks]
incoming = .hg\write_buildrequest_file.bat

In .hg\write_buildrequest_file.bat

echo REQUESTBUILD > \REQUESTBUILD

Meanwhile, I had a python script running in an infinite loop, checking for the presence of REQUESTBUILD.

In .hg\monitor_buildrequest_file.py

import popen2, time, os
import subprocess

while True:
    if os.path.exists("\REQUESTBUILD"):
        os.system("del \REQUESTBUILD")
        os.chdir("/yourrepo/.hg")
        retcode = subprocess.call("\python27\python.exe build.py")
    else:
        time.sleep(10)

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.

岛歌少女 2024-10-14 06:30:41

您需要使用钩子处理存储库事件

因此,在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文