5
votes

I am trying to perform a full git fetch from my build agent, in order to use GitVersion in TeamCity.

I have opted to use the agent checkout option in TeamCity, as per http://gitversion.readthedocs.io/en/latest/build-server-support/build-server/teamcity/#agent-checkout

However, when I perform a checkout on the agent, I'm unable to get the full git history for a branch. I get the same result as this: https://github.com/GitTools/GitVersion/issues/912 - Specifically:

System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.

My guess is this is because TeamCity is only checking out a subset of the repo history.

The Github issue has a workaround of performing a git fetch command at the start of every build. Is this something that TeamCity can natively support as part of a VCS root?

Thanks in advance

2
Anyone got a solution to this yet? Yes, I'm specifying the /output buildserver option. And it never happens on the original build server, only on the new build agent that I just spun up. The original one is running on the same machine as TeamCity if that matters. Running Team City version 2017.2.3 (build 51047) if that matters.Traderhut Games
If I go to that build directory and type the git fetch --all and then run gitversion it works correctly, however, because we remove the folder on a new build, this doesn't solve the issue - unless we wanted to add it as a build step to every project we have! Clearly, the other build server has something this one lacks.Traderhut Games
running the latest gitversion on the new build server: 4.0.0+Branch.master.Sha.e715eb5dd515037d90a257f527e62442cae8c1c5 . On the old build server, it is a version before /version worked.Traderhut Games
According to Chocolatey (choco version gitversion) they are both 1.0.0.1, so clearly, the fact that they don't function the same is weird..Traderhut Games

2 Answers

2
votes

TeamCity has the ability to fetch all heads TeamCity since v2017, but needs to be enabled via a config setting.

You can configure Git-plugin to fetch all heads by adding a build configuration parameter:

teamcity.git.fetchAllHeads=true.

See here for more details:

0
votes

Can you show the command line arguments that you are passing to GitVersion when running on TeamCity? Are you specifying the /output buildserver option? When this is enabled, GitVersion goes through a branch normalisation process, to ensure that all required branches are fetched from the repository.