Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not trigger a build in Teamcity if only a specific file changed

I am working with Teamcity as a build manager on a git repository;

currently, the trigger for creating a new build is if there are new changes.

the problem is, when building, the script i run creates a new commit of a specific file called version.txt (i increment the number there).

While finishing successfully, the commit is considered as a new change and on the next run , even if no other commits were made, the nightly build will be triggered.

I want to be able to create a rule that will not trigger a build if the only change pending is to the Version.txt file.

is there a way of doing that?

edit: I've added a condition rule to team city: do not trigger a build if version.txt file has changed(see screenshot) however, it seems this rule will cause the build not to be triggered if ,for instance, there are 2 pending changes which one of them is to the version.txt file

enter image description here

thanks in advance.

like image 841
Imaybewrong Avatar asked Oct 18 '22 19:10

Imaybewrong


1 Answers

Yep, you can do it.
Here are several options:


Update the version.txt before you execute the build.

Use a git hook to capture the commit and then you can update the build and commit it so you will have 2 commits which will your build will execute - the original one + the version update


Git hooks

Check in the commit hook for the files which are being committed. If the only file is the version then skip the build

Here is an example of post-merge hook which runs after the user push code to the remote branch

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

Use smudge to update the version

The version increment will be done when adding code to the index (git add) enter image description here

like image 105
CodeWizard Avatar answered Oct 21 '22 22:10

CodeWizard