gpt4 book ai didi

git - 如何在持续集成构建服务器上使用 git

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

我们有一个构建服务器,旨在从 git 中 check out 一个版本的代码并构建它。通常服务器会 checkout 并构建 develop分支,但它可以由 GUI 控制以执行任何特定分支或标记的构建。

我们的 git 存档很大,所以我们只想执行 git clone一次。所以我的问题是:应该发出什么顺序的 git 命令,以使当前工作目录相对于远程 git 存档是最新的。

我最初天真的尝试只是执行了 git checkout <branch>其次是 git pull .但这并没有考虑到之前构建创建的所有需要​​删除的工件,以及构建过程中进行的一些自动代码修改,例如到程序集文件中的版本号。

所以我认为我们需要的是命令序列

  1. 摆脱对本地目录的任何修改
  2. 更新本地存储库以包含来自远程服务器的所有提交
  3. checkout 指定的分支或标签

请记住,指定的分支或标签在本地存储库中可能是未知的。例如,如果一个新的 release/xxx分支是在远程服务器上创建的,这对于本地构建机器来说是先验的。这是我天真的方法偶然发现的另一个问题。

最后,git 服务器可能偶尔会更正它的历史记录。我确信这将是一个罕见的事件,但如果集成服务器在历史记录重写后不需要任何调整,那将是可取的。

非常感谢

最佳答案

这是我们目前使用的机制。 git clone 作为设置的一部分只执行一次,然后对每个构建执行以下操作。

为了清楚起见,我删除了错误处理。


# Undo any modifications made to the working tree by the build process

git reset --hard

# Remove any untracked build artifacts created by the build process

git clean -fdx

# Fetch all commits and new branches/tags from the git server.

git fetch

# Set the index and working directory to the required tag or branch.
# Notes:
# * If the last build was for the same branch, then this will not
# update the working directory.
# * The %TAG_OR_BRANCH% variable is passed in via the GUI. This will
# be in the form of a branch name (develop|release/vX.X.X) or a tag (vX.X.X)

git checkout %TAG_OR_BRANCH%

# Bring the index and working tree up-to-date.
# Notes:
# * the --ff-only flag is probably redundant, but we want to make it
# clear that no merging is expected.

git pull --ff-only

我们在开发人员机器上创建了新的标签/分支,将它们推送到服务器,这个脚本正确地获取它们并构建结果。我们尝试将 origin/ 前缀添加到分支或标签名称,但这种方法对我们不起作用(无法识别标签名称)。

我认为这个脚本和@Yasser 建议的更简单的答案之间的主要区别是 git HEAD 指向正确的位置和命令 git status给出了一个明智的答案。这是否重要 - 我不确定。

关于git - 如何在持续集成构建服务器上使用 git,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37122520/

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