Jenkins构建成功后,如何将更改从一个分支推送到另一个分支? [英] How do I push changes from one branch to another branch after a successful Jenkins build?

查看:437
本文介绍了Jenkins构建成功后,如何将更改从一个分支推送到另一个分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jenkins构建成功后,如何将更改从一个分支推送到另一个分支?假设我有一个名为beta的分支,我承诺将另一个命名为主,我想包含所有提交到beta的提交都是成功的。 解决方案




设置Jenkins插件的高级功能部分建立你的Jenkins项目,并将Git
SCM中的'branch'字段留空。这将导致Jenkins考虑对任何
分支进行构建的任何更改。

接下来,在
中选择一个特定的分支名称作为集成目标'高级'部分 - (例如'master'或'stable'),并选择'合并之前的
'。

选择'到源代码仓库'后期构建的
操作(这需要使用构建的
结果更新您的集中式git仓库)。



现在,开发人员不应直接向您的集成
分支('主'或'stable')提交。相反,他们应该使用
特性分支,或者在提交时创建新的远程分支(例如:git
push origin HEAD:refs / heads / myNewFeature)。您也可以将您的
GIT存储库设置为仅接受来自
Jenkins的整合分支的提交。



您完成了。提交现在应该与
集成分支自动合并(如果他们不干净地把他们会失败),和
内置。如果构建成功,合并的结果将被推回到远程git存储库。

一些阐述基于我对插件的使用经验:


  1. 我选择在我的原始存储库中创建一个名为beta的分支。另外,我决定只在更新分支时创建,因此我将分支构建字段设置为* / beta。


  2. 我必须添加一个额外的行为合并之前构建 - 它不只是坐在那里供我选择。本节的存储库名称是origin,合并到的分支是master。

  3. 我还选择了一个后期构建Git Publisher的动作。为此,我同时选中了仅限制建立成功和合并结果框。我还在分支中写下了master,以便在目标远程名称中推送方框和origin。

< a href =https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin =nofollow> https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin


How do I push changes from one branch to another branch after a successful Jenkins build? Suppose I have a branch named "beta" that I commit to and another named "master" that I want to contain all commits to beta that are successful.

解决方案

From the Advanced Features section of the writeup for the Jenkins plugin available at the link at the bottom:

Set up your Jenkins project, and leave the 'branch' field in the Git SCM blank. This will cause Jenkins to consider any change on any branch for building.

Next, pick a particular branch name as the integration target in the 'Advanced' section - (e.g. 'master', or 'stable'), and select 'Merge before build'.

Select 'Push GIT tags back to origin repository' from the post-build actions (this is required to update your centralised git repo with the results of the build).

Now, developers should never commit directly to your integration branch (the 'master' or 'stable'). Instead, they should either use feature branches, or create new remote branches on commit (e.g : "git push origin HEAD:refs/heads/myNewFeature"). You could also set up your GIT repository to only accept commits onto the integration branch from Jenkins.

You're done. Commits should now be automatically merged with the integration branch (they will fail if they do not merge cleanly), and built. If the build succeeds, the result of the merge will be pushed back to the remote git repository.

A few elaborations based on my experience with the plugin:

  1. I chose to create a branch named "beta" in my original repository. Also, I decided that I only wanted to build when this branch was updated, so I set the "Branches to build" field to "*/beta".

  2. I had to "Add an additional behaviour" of "merge before build" -- it wasn't just sitting there for me to select. The name of the repository for me for this section was "origin" and the branch to merge to was "master".

  3. I also selected a post-build action of "Git Publisher". For this I checked both the box for "Push Only If Build Succeeds", and "Merge Results". I also wrote "master" in the Branch to push box and "origin" in the target remote name.

https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin

这篇关于Jenkins构建成功后,如何将更改从一个分支推送到另一个分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆