【问题标题】:How to not trigger a build in Teamcity if only a specific file changed如果仅更改特定文件,如何不触发 Teamcity 中的构建
【发布时间】:2015-12-29 07:14:54
【问题描述】:

我作为 git 存储库的构建经理与 Teamcity 合作;

目前,创建新构建的触发器是是否有新的更改。

问题是,在构建时,我运行的脚本会创建一个名为 version.txt 的特定文件的新提交(我在那里增加数字)。

成功完成后,该提交被视为新的更改,并且在下一次运行时,即使没有进行其他提交,也会触发夜间构建。

如果唯一未决的更改是 Version.txt 文件,我希望能够创建一个不会触发构建的规则。

有没有办法做到这一点?

编辑: 我已向团队城市添加了条件规则:如果 version.txt 文件已更改,则不触发构建(见截图) 但是,如果有 2 个待定更改,其中一个是对 version.txt 文件的更改,则此规则似乎会导致构建不被触发

提前致谢。

【问题讨论】:

    标签: git build triggers teamcity


    【解决方案1】:

    是的,你可以做到。
    这里有几个选项:


    在执行构建之前更新version.txt

    使用 git 钩子捕获提交,然后您可以更新构建并提交它,这样您将有 2 个提交将执行您的构建 - 原始一个 + 版本更新


    Git 钩子

    在提交钩子中检查正在提交的文件。 如果唯一的文件是版本,则跳过构建

    这是一个post-merge钩子的例子,它在用户将代码推送到远程分支之后运行

    #!/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

    【讨论】:

    • 感谢 codeWizard 的详细解答!但是,此时,我想知道是否有一个解决方案不需要更改脚本与 git 存储库交互方式的任何行为,而是针对触发规则问题的 Teamcity 相关解决方案。
    • > ... 需要更改脚本与 git 存储库交互方式的任何行为。 |您可以使用与本地存储库无关的服务器端挂钩
    猜你喜欢
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-02
    • 2010-11-22
    相关资源
    最近更新 更多