我正在与Teamcity合作,作为git存储库上的生成管理器;
当前,创建新版本的触发器是是否有新更改。
问题是,在构建时,我运行的脚本会创建一个名为version.txt的特定文件的新提交(我在那里增加数字)。
成功完成后,提交将被视为新更改,并且在下一次运行时,即使未进行其他提交,也会触发夜间构建。
我希望能够创建一个规则,如果仅待处理的更改是对Version.txt文件的更改,则该规则将不会触发生成。
有没有办法做到这一点?
编辑:
我已经向团队城市添加了条件规则:如果version.txt文件已更改,请不要触发构建(请参见屏幕截图)
但是,如果,例如,有2个待处理的更改(其中之一是对version.txt文件的更改),似乎该规则将导致不触发生成。
提前致谢。
最佳答案
是的,您可以做到。
以下是几个选项:
在执行构建之前,请更新version.txt
。
使用git钩子(Hook)捕获提交,然后您可以更新构建并将其提交,因此您将有2次提交将执行您的构建-原始提交+版本更新
吊钩
在提交 Hook 中检查要提交的文件。
如果唯一的文件是版本,则跳过构建
这是post-merge
钩子(Hook)的示例,该钩子(Hook)在用户将代码推送到远程分支后运行
#!/bin/sh
# Check to see if this is the first commit in the repository or not
if git rev-parse --verify HEAD >/dev/null 2>&1
then
# We compare our changes against the prevoius commit
against=HEAD^
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# Redirect output to screen.
exec 1>&2
# Check to see if we have updated the version.txt file
if [ $(git diff-tree -r --name-only $against | grep version.txt ) ];
then
# Output colors
red='\033[0;31m';
green='\033[0;32m';
yellow='\033[0;33m';
default='\033[0;m';
# personal touch :-)
echo "${red}"
echo " "
echo " |ZZzzz "
echo " | "
echo " | "
echo " |ZZzzz /^\ |ZZzzz "
echo " | |~~~| | "
echo " | |- -| / \ "
echo " /^\ |[]+ | |^^^| "
echo " |^^^^^^^| | +[]| | | "
echo " | +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^| "
echo " |+[]+ |~~~~~~~~~~~~~~~~~~| +[]| "
echo " | | [] /^\ [] |+[]+ | "
echo " | +[]+| [] || || [] | +[]+| "
echo " |[]+ | || || |[]+ | "
echo " |_______|------------------|_______| "
echo " "
echo " "
echo " ${green}You have just commited code ${red} "
echo " Your code ${yellow}is bad.!!! ${red} Do not ever commit again "
echo " "
echo "${no_color}"
#fi;
exit 0;
使用涂抹来更新版本
将代码添加到索引(
git add
)时,将完成版本增量