詹金斯和多个 git 分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7288359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jenkins and multiple git branches?
提问by Marx
I'm working on a Jenkins job and i need it to build two branches in the same repository. How can i do this?
我正在从事 Jenkins 的工作,我需要它在同一个存储库中构建两个分支。我怎样才能做到这一点?
回答by VonC
Considering that Jenkins cannot execute one job on twoversions 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).
考虑到 Jenkins 无法在存储库的两个版本上执行一项作业(这将获取两个不同分支的内容),我建议制作两个不同的作业,每个分支一个(使用Jenkins Git 插件)。
回答by alvinabad
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.
这个单个脚本将成为单个 Jenkins 作业调用的脚本。
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.
更新:如果您想为下一次构建拥有一个新的工作区,请使用 git clean -xdf 。
回答by cedd
This plugin will build every branch for you: https://wiki.jenkins-ci.org/display/JENKINS/Multi-Branch+Project+Plugin.
该插件将为您构建每个分支: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.
你也可以使用 GitLab ( https://wiki.jenkins-ci.org/display/JENKINS/GitLab+Plugin) / GitHub ( https://wiki.jenkins-ci.org/display/JENKINS/GitHub+Plugin)插件,它可以在提交代码时触发构建,然后将构建提交的分支。
回答by Dean Hiller
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).
如果您想要上述内容并且想要 Jenkins 构建任何新分支并仅在构建成功时将其合并到 master 的高级功能(即您想要两个主分支和两个构建),您可能需要考虑只分叉存储库和合并存储库之间的更改(git 是为那种事情而构建的,尽管我还没有完全达到那个使用点)。
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.
因此,您基本上会有 2 个 git 存储库和两个 jenkins 构建,您可以配置 git 插件以从每个存储库中的任何分支构建并合并到该存储库的 master 中。因此,每个存储库在此配置中就像一个分支。
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.
这就是我们的计划,当我们从 1.x 发布行开始新的 2.x 发布行时,无论如何要分叉。我们将看到它在实践中是如何工作的。
later, Dean
后来,迪恩