TeamCity - 如何组合 VCS 触发器
TeamCity - how to combine VCS Triggers
情况如下:在 git 回购中我有 3 个文件夹:
一种
乙
C
如果对 A 或 C 进行了更改,则必须开始构建。在任何其他情况下,如果对 B 也进行了更改,则不应启动它。如何使用 TeamCity VCS 触发器实现此类行为?
您应该为该 VCS 根配置 VCS 触发规则。
添加 VCS 触发器 as usual,然后将其添加到规则中:
-:B/**
这将触发 VCS 根目录中的所有内容,文件夹 B 除外。
或者您可以采用不同的方式,仅针对 A 或 C 文件夹中的更改触发构建:
+:A/**
+:C/**
这会起作用,因为
When entering rules, please note that as soon as you enter any "+"
rule, TeamCity will remove the default "include all" setting. To
include all the files, use "+:." rule.
我没有找到去"prevent build from start if there are changes in particular folder"的路。构建将开始。但我决定采取解决方法,如果检测到 B 文件夹中的更改,则跳过后续步骤的实际执行。下面是给我环境变量的脚本,可以优雅地避免执行下一个构建步骤。
此脚本基于 TeamCity 环境变量
%system.teamcity.build.changedFiles.file%
重要提示:不要使用 -:B(在我的例子中是 -:lisp)触发规则,否则你将无法从脚本中检测到此文件夹中的更改。
脚本:
#!/bin/bash
listFiles=$(echo %system.teamcity.build.changedFiles.file%)
echo "List files from $listFiles"
echo "--------------------------"
cat $listFiles
echo "--------------------------"
lispFound=$(cat $listFiles | grep -c '^src\/lisp\/*.')
echo "LISP CHANGES WERE DETECTED: $lispFound time(s)"
echo "##teamcity[setParameter name='env.LISP_CHANGES_DETECTED' value ='$lispFound']"
因此,包含已更改文件数的 %env.LISP_CHANGES_DETECTED% 将在任何下一步中可用。在我的情况下,下一步是 Ant,并且可以在任何目标中检测是否应该回显 "nothing to do" 并退出。这是执行日志的例子:
改进:
如此处所述 Can I cancel a TeamCity build from my msbuild script?
可以从脚本中正常停止执行,您需要添加取消执行的调用:
curl -v -u user:password --request POST "http://teamcity:8111/app/rest/builds/<buildLocator>" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"
情况如下:在 git 回购中我有 3 个文件夹: 一种 乙 C 如果对 A 或 C 进行了更改,则必须开始构建。在任何其他情况下,如果对 B 也进行了更改,则不应启动它。如何使用 TeamCity VCS 触发器实现此类行为?
您应该为该 VCS 根配置 VCS 触发规则。 添加 VCS 触发器 as usual,然后将其添加到规则中:
-:B/**
这将触发 VCS 根目录中的所有内容,文件夹 B 除外。 或者您可以采用不同的方式,仅针对 A 或 C 文件夹中的更改触发构建:
+:A/**
+:C/**
这会起作用,因为
When entering rules, please note that as soon as you enter any "+" rule, TeamCity will remove the default "include all" setting. To include all the files, use "+:." rule.
我没有找到去"prevent build from start if there are changes in particular folder"的路。构建将开始。但我决定采取解决方法,如果检测到 B 文件夹中的更改,则跳过后续步骤的实际执行。下面是给我环境变量的脚本,可以优雅地避免执行下一个构建步骤。
此脚本基于 TeamCity 环境变量
%system.teamcity.build.changedFiles.file%
重要提示:不要使用 -:B(在我的例子中是 -:lisp)触发规则,否则你将无法从脚本中检测到此文件夹中的更改。
脚本:
#!/bin/bash
listFiles=$(echo %system.teamcity.build.changedFiles.file%)
echo "List files from $listFiles"
echo "--------------------------"
cat $listFiles
echo "--------------------------"
lispFound=$(cat $listFiles | grep -c '^src\/lisp\/*.')
echo "LISP CHANGES WERE DETECTED: $lispFound time(s)"
echo "##teamcity[setParameter name='env.LISP_CHANGES_DETECTED' value ='$lispFound']"
因此,包含已更改文件数的 %env.LISP_CHANGES_DETECTED% 将在任何下一步中可用。在我的情况下,下一步是 Ant,并且可以在任何目标中检测是否应该回显 "nothing to do" 并退出。这是执行日志的例子:
改进: 如此处所述 Can I cancel a TeamCity build from my msbuild script?
可以从脚本中正常停止执行,您需要添加取消执行的调用:
curl -v -u user:password --request POST "http://teamcity:8111/app/rest/builds/<buildLocator>" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"