![](/img/trans.png)
[英]How can a commit in git submodule trigger a build in continuous integration?
[英]How to use git on a continuous integration build server
我们有一个构建服务器,用于从git签出代码版本并构建它。 通常,服务器将签出并构建develop
分支,但它可以由GUI控制以执行任何特定分支或标记的构建。
我们的git存档很大,所以我们只想执行一次git clone
。 所以我的问题是:应该发出什么样的git命令序列,以便使当前工作目录与远程git档案保持同步。
我最初的天真尝试只是执行了git checkout <branch>
然后是git pull
。 但是这没有考虑到需要删除的先前构建所创建的所有工件以及构建过程所做的一些自动代码修改,例如汇编文件中的版本号。
所以我认为我们需要的是命令序列
请记住,本地存储库中可能尚未知道指定的分支或标记。 例如,如果在远程服务器上创建了新的release/xxx
分支,则不会事先知道本地构建机器。 这是我天真的方法偶然发现的另一个问题。
最后,git服务器可能偶尔会更正它的历史记录。 我确信这将是一个罕见的事件,但如果集成服务器在历史重写后不需要任何调整,那将是可取的。
非常感谢
假设您正确设置了.gitignore
,您应该能够做到
git fetch
git reset --hard origin/branch
git clean -xfd
这应该产生一个干净的构建。
这是我们目前使用的机制。 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
给出了明智的答案。 这是否重要 - 我不确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.