使用 Hudson 并通过多个 git 存储库构建步骤

发布于 2024-08-12 14:34:37 字数 845 浏览 8 评论 0原文

我正在尝试使用 Hudson 来替换我们当前的 Buildbot 设置。我安装了 git 插件。我们当前的设置如下:

ssh://server:/repo/test_framework.git
ssh://server:/repo/project_a.git

现在,为了构建 project_a,我添加了一个包含多个 git 存储库(上面的)的新作业。我希望 Hudson 将存储库克隆到 $WORKSPACE 下的不同目录中,因为 test_framework 需要该层次结构。但 Hudson 似乎将所有内容合并到 $WORKSPACE 中。从控制台日志:

warning: no common commits
...
[workspace] $ git merge-base ce14a4579e87971659e5e0469136713847055a29 96d2b3c27595de243702414c4358366923696d78
[workspace] $ git merge-base ce14a4579e87971659e5e0469136713847055a29 5bb011b3fa288afd5e4392640b32b8bcc982103e
[workspace] $ git merge-base ce14a4579e87971659e5e0469136713847055a29 aa6ade81669883909ba5f5459a205df1bd0df3c0

我可以在 Hudson 中配置它以更好地适应我们的项目设置吗?我是否需要为每个项目创建一个本地虚拟 git 存储库作为 git 子模块或其他东西?

I'm trying out Hudson to replace our current Buildbot setup. I installed the git plugin. Our current setup is like:

ssh://server:/repo/test_framework.git
ssh://server:/repo/project_a.git

Now, to build project_a I added a new job with multiple git repositories (the ones above). I wanted Hudson to clone the repositories into different directories under $WORKSPACE, becase test_framework needs that hierarchy. But Hudson seems to merge everything into $WORKSPACE instead. From the console log:

warning: no common commits
...
[workspace] $ git merge-base ce14a4579e87971659e5e0469136713847055a29 96d2b3c27595de243702414c4358366923696d78
[workspace] $ git merge-base ce14a4579e87971659e5e0469136713847055a29 5bb011b3fa288afd5e4392640b32b8bcc982103e
[workspace] $ git merge-base ce14a4579e87971659e5e0469136713847055a29 aa6ade81669883909ba5f5459a205df1bd0df3c0

Can I configure this in Hudson to better fit our project setup? Do I need to create a local dummy git repository with every project as git submodules or something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

数理化全能战士 2024-08-19 14:34:37

在 Hudson 中,您可以将多个工作链接在一起。您可以尝试为 test_framework 创建单独的 Hudson 作业,并为 project_a 创建另一个作业。 Hudson 在 $WORKSPACE 中为每个作业创建一个单独的目录,因此现在 $WORKSPACE 下应该有两个不同的目录。


设置链接

在project_a的作业配置中,向下滚动到构建后操作并选中构建其他项目... 在test_framework中输入作为要构建的项目。

在 test_framework 的作业配置中,确保 Poll SCM 未选中,并将 Build after other items 设置为 project_a。


工作原理

您现在配置的是project_a将轮询SCM以查找更改,当发现更改时,它将从git中提取它们。运行构建步骤(如果有)并在完成时触发 test_framework 作业从 git 中提取更改(如果有)并运行其构建步骤。

Within Hudson you can chain multiple jobs together. You could try creating separate Hudson jobs for test_framework and another for project_a. Hudson creates a separate directory in $WORKSPACE for each job, so now you should have two different directories under $WORKSPACE.


Setup Chaining

In the job configuration of project_a scroll down to Post-build actions and check Build other projects... Enter in test_framework as the project to build.

In the job configuration of test_framework ensure that Poll SCM is unchecked and that Build after other projects is set to project_a.


How it works

What you have now configured is project_a will poll the SCM looking for changes, when changes are found it will pull them from git. Run build steps (if any) and on completion trigger the test_framework job to pull changes from git (if any) and run its build steps.

予囚 2024-08-19 14:34:37

“构建其他项目”解决方案的问题是,如果 test_framework 发生更改,它将不会触发 project_a 进行构建。相反,我建议放弃 git 插件并使用以下内容设置“执行 shell”构建步骤:

rm -rf ${WORKSPACE}/*

git clone ssh://server:/repo/test_framework.git ${WORKSPACE}/test_framework
cd ${WORKSPACE}/test_framework
git fetch -t ssh://user@server:/repo/test_framework.git +refs/heads/*:refs/remotes/origin/*
git ls-tree HEAD

git clone ssh://server:/repo/project_a.git ${WORKSPACE}/project_a
cd ${WORKSPACE}/project_a
git fetch -t ssh://user@server:/repo/project_a.git +refs/heads/*:refs/remotes/origin/*
git ls-tree HEAD

接下来,创建挂钩文件“server:/repo/test_framework.git/hooks/post-receive”和“server:/repo/ project_a.git/hooks/post-receive”包含以下内容:

#!/bin/sh
curl http://hudson/job/job_name/build

现在,每当将更改推送到任一存储库时,挂钩将使用 Hudson 的 API 来触发构建。

The problem with the "Build other projects" solution is that if there are changes to test_framework it will not trigger project_a to build. Instead, I recommend abandoning the git plugin and setting up an "Execute shell" build step with the following:

rm -rf ${WORKSPACE}/*

git clone ssh://server:/repo/test_framework.git ${WORKSPACE}/test_framework
cd ${WORKSPACE}/test_framework
git fetch -t ssh://user@server:/repo/test_framework.git +refs/heads/*:refs/remotes/origin/*
git ls-tree HEAD

git clone ssh://server:/repo/project_a.git ${WORKSPACE}/project_a
cd ${WORKSPACE}/project_a
git fetch -t ssh://user@server:/repo/project_a.git +refs/heads/*:refs/remotes/origin/*
git ls-tree HEAD

Next, create hook files "server:/repo/test_framework.git/hooks/post-receive" and "server:/repo/project_a.git/hooks/post-receive" with the following content:

#!/bin/sh
curl http://hudson/job/job_name/build

Now, whenever changes are pushed to either repository, the hook will use Hudson's API to trigger a build.

黒涩兲箜 2024-08-19 14:34:37

我意识到这个问题很老了,但我遇到了同样的问题,并使用此页面来充实我自己的解决方案,该解决方案似乎工作得很好(尽管它有点复杂)。这个解决方案的大部分功劳应该归功于克林顿(我费心提交这个答案的唯一原因是因为他的答案似乎没有解决需要位于同一基目录中的多个存储库)。

假设您有两个存储库(A 和 B)。

步骤:

1) 创建两个项目以从远程存储库 A 和 B 中提取代码。将任何必要的构建步骤放入任一存储库中。

2)创建第三个目录,不进行任何源代码控制管理。向该项目添加一个构建步骤,以执行与此类似的 shell 命令:(

ln -s /var/lib/jenkins/jobs/A/workspace A
ln -s /var/lib/jenkins/jobs/B/workspace B

您的路径可能不同。请自行查找!)

现在您可以添加依赖于 A 和 B 在目录中是姐妹关系的任何其他构建步骤。是的符号链接!

3)将三个任务链接在一起。拉取任务的顺序可能重要也可能不重要(你比我更清楚),但没有源代码控制的任务应该是链中的最后一个环节。

I realize this question is very old but I ran into the same problem and used this page to flesh out my own solution that seems to be working really well (even though it is a tad convoluted). Most of the credit for this solution should go to Clinton (the only reason I'm bothering to submit this answer is because his answer doesn't seem to address multiple repositories that need to be in the same base directory).

Suppose you have two repositories (A and B).

Steps:

1) Make two projects to pull code from remote repositories A and B. Put any necessary build steps in either repository.

2) Make a third directory without any source control management. Add a build step to this project to execute a shell command similar to this:

ln -s /var/lib/jenkins/jobs/A/workspace A
ln -s /var/lib/jenkins/jobs/B/workspace B

(Your paths may not be the same. Look them up yourself!)

Now you can add any other build steps that depend on A and B being sisters in a directory. Yay symbolic links!

3) Chain the three tasks together. The order of the pull tasks may or may not matter (you know better than I do) but the task without source control should be the last link in the chain.

一世旳自豪 2024-08-19 14:34:37

我遇到了同样的问题,目前通过为每个项目创建一个作业并使用 Copy Artifact Plugin 允许构建依赖作业,即使对其依赖项进行了 Git 更新(这是为了避免在我们依赖的项目更新过程中进行构建)。

因此,project_a 将从 test_framework 复制所需的最新稳定工件,并且对测试框架的更新将触发 project_a 中的构建。 project_a 仍然可以由 Git 中的更改触发,它只是再次复制 test_framework 中的最新工件。

I ran into the same problem and currently solved it by creating a job for each project and using the Copy Artifact Plugin to allow building the dependent job even if a Git update is done on it's dependencies (this is to avoid building in the middle of an update to the project which we depend upon).

So project_a would copy the latest stable artifacts it needs from test_framework and an update to test framework would trigger a build in project_a. project_a can still be triggered by a change in Git, it just copies again the latest artifacts in test_framework.

活雷疯 2024-08-19 14:34:37

您描述的问题已在 Jenkins bugtracker 中作为错误归档:https://issues。 jenkins-ci.org/browse/JENKINS-8082


我们使用扩展项目作业配置中的“自定义工作区”选项将作业的存储库检出到另一个作业的子目录中。

其他作业检查主目录及其所有子模块:

var/lib/jenkins/jobs/
  + main_job
    + workspace (main git checkout with submodules)
      + modules
        + mod1
        + mod2
  + mod1_job (custom workspace set to main_job/workspace/modules/mod1)
    + workspace (empty)

The problem you are describing is already filed as bug in the Jenkins bugtracker: https://issues.jenkins-ci.org/browse/JENKINS-8082


We use the "custom workspace" option in the extended project job configuration to checkout our job's repository into a subdirectory of another job.

That other job checks out the main directory with all submodules:

var/lib/jenkins/jobs/
  + main_job
    + workspace (main git checkout with submodules)
      + modules
        + mod1
        + mod2
  + mod1_job (custom workspace set to main_job/workspace/modules/mod1)
    + workspace (empty)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文