Jenkins 和多个 git 分支?

发布于 2024-12-02 14:47:09 字数 49 浏览 3 评论 0原文

我正在从事 Jenkins 工作,我需要它在同一个存储库中构建两个分支。我该怎么做?

I'm working on a Jenkins job and i need it to build two branches in the same repository. How can i do this?

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

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

发布评论

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

评论(4

故笙诉离歌 2024-12-09 14:47:09

考虑到 Jenkins 无法在存储库的两个版本上执行一项作业(这将获取两个不同分支的内容),我建议创建两项不同的作业,每个分支一个(使用Jenkins Git 插件)。

Considering that Jenkins cannot execute one job on two versions of a repository (which is what would be getting the content of two different branches), I would suggest making two different jobs, one for each branch (with the Jenkins Git plugin).

极致的悲 2024-12-09 14:47:09

您是否想在同一个签出工作区目录中构建两个分支?

如果在同一工作区目录中,您所需要做的就是创建一个脚本,该脚本将签出一个分支,构建它,完成后签出下一个分支,然后构建它。

然后,这个脚本将被单个 Jenkins 作业调用。

例如,您的构建脚本将如下所示:

git clone url:repo.git workspace
cd workspace 
git checkout branchA
make
# now you're done building branchA
# next checkout branchB and run make
git checkout branchB
make
# now you are done building branchB

每次签出都会安装所需分支的文件。这将相应地构建它。但是,由于它们将共享相同的工作区目录,这可能意味着第一个构建将生成新文件,然后在第二个构建运行时将出现新文件。我认为这就是您想要的效果,因为您想在同一工作区目录中构建两个分支。

更新:如果您想为下一个构建提供新的工作空间,请使用 git clean -xdf。

Are you asking if you want to build two branches in the same checked-out workspace directory?

If in the same workspace directory, all you need to do is create a script that will checkout one branch, build it, and when done, checkout the next branch and then build it.

This single script will then be the one to be called by the single Jenkins job.

For example, your build script would look something like this:

git clone url:repo.git workspace
cd workspace 
git checkout branchA
make
# now you're done building branchA
# next checkout branchB and run make
git checkout branchB
make
# now you are done building branchB

Each checkout will install the files for the branch desired. And this will build it accordingly. However, since they will be sharing the same workspace directory, this could mean that new files would be produced by the first build which will then be present when the second build runs. I assume this is the effect that you want because you wanted to build two branches in the same workspace directory.

Update: Use git clean -xdf if you want to have a fresh workspace for the next build.

心房的律动 2024-12-09 14:47:09

该插件将为您构建每个分支:https://wiki。 jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin

您还可以使用 GitLab (https://wiki.jenkins-ci.org/显示/JENKINS/GitLab+Plugin) / GitHub (https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin) 插件,可以在提交代码时触发构建,然后构建之前的分支致力于。

This plugin will build every branch for you: https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin.

You can also use the GitLab (https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin) / GitHub (https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin) plugins, which can trigger a build when code is commited, and will then build the branch that was comitted to.

简单气质女生网名 2024-12-09 14:47:09

如果您想要上述功能并且想要 Jenkins 构建任何新分支并仅在构建成功时将其合并到 master 的高级功能(即您想要两个 master 分支和两个构建),您可能需要考虑只分叉存储库并合并存储库之间的更改(git 是为此类事情而构建的,尽管我还没有完全达到使用的目的)。

所以你基本上会有 2 个 git 存储库和两个 jenkins 构建,你可以配置 git 插件从每个存储库中的任何分支构建并合并到该存储库的 master 中。因此,每个存储库在此配置中都充当一个分支。

这就是我们的计划,当我们从 1.x 发布线开始新的发布线 2.x 时,无论如何都是要分叉。我们将看看它在实践中是如何运作的。

之后,
院长

IF you want the above AND want the advanced feature where Jenkins builds any new branch and merges that to master ONLY if the build succeeds(ie. you want two master branches and two builds), you may want to think about just forking the repository and merging changes between repositories(git is built for that kind of thing though I have not quite gotten to that point of usage yet).

So you would basically have 2 git repositories and two jenkins builds and you can configure the git plugin to build from any branch in each repository and merge into master of that repository. So, each repository is acting like a branch in this configuration.

That is our plan when we start a new release line 2.x from our 1.x release line at any rate is to fork. We will see how it works in practice.

later,
Dean

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