gpt4 book ai didi

git - 如何仅对我要 merge 的分支使用 Jenkins 预构建分支 merge ?

转载 作者:IT王子 更新时间:2023-10-29 01:02:28 25 4
gpt4 key购买 nike

我正在阅读 https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-AdvancedFeatures这允许在将提交推送到主分支之前预先构建功能分支,从而有效地实现预提交构建/测试队列。

它在 Using Git, Jenkins and pre-build branch merging 下说:

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.

现在我经常有我想继续开发的功能分支,并且稍后才将它们 merge 到 master 中。

据我所知,此设置会在构建后立即 merge 任何功能分支并将其推送到master

(如何)Jenkins 能否支持我的用例,构建所有功能分支,但仅将那些 merge 到我打算 merge 的 master 中?

最佳答案

我有一个构建管道,我只希望开发分支 merge 回我的稳定分支。所有其他人不应 merge 。我解决这个问题的方法是有一个单独的 merge 工作。构建作业完成后,仅当环境变量 GIT_BRANCH 等于“开发”时才会触发“merge ”作业。

Jenkins 没有一个非常好的条件触发器可以按我想要的方式工作。以下是我如何设置构建作业以有条件地触发 merge 步骤。

  • 添加构建步骤以删除名为 trigger.properties 的文件(我使用 Execute Shell 构建步骤)
  • 添加构建步骤(条件构建步骤插件) 如果 $GIT_BRANCH 等于“origin/develop”,则运行条件步骤(单个)。当为真时,它运行一个 shell 命令来创建 trigger.properties 文件。 (触摸触发器。属性)
  • 添加构建后操作(参数化触发器插件)以在构建稳定时触发我的 merge 作业。在“来自属性文件的参数”部分中,用“trigger.properties”填写字段。有一个选项“如果缺少任何文件则不触发”,因此请检查它。

所以这个过程是首先删除 trigger.properties 文件以确保之前的运行没有冲突。然后,检查git分支是否是develop。如果是,请重新创建 trigger.properties 文件。构建后步骤需要该文件存在才能触发下一个作业。

现在,您可以在专为此而设计的工作中执行您喜欢的各种 merge 。您还可以修改此过程,以便多个分支进入 merge 作业。

关于git - 如何仅对我要 merge 的分支使用 Jenkins 预构建分支 merge ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22732145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com