Some Teamcity agent hosts do not have access to git master branch

We have the following setup for TeamCity :

VCS is Git

VCS root setting

------------------------

Default branch: refs/heads/develop

Branch Specification :
+:refs/heads/(develop)
+:refs/heads/(master)

The build is triggered whenever there is a commit to the 'develop' branch.

We have a command-line build step which runs a bash script.
In the bash script, I try to find the merge base of the develop branch with the master branch via the following commands:

branchName=$(git rev-parse --abbrev-ref HEAD)
git merge-base $branchName master

We see that there are certain agent hosts on which we get an error:

[Step 4/4] fatal: Not a valid object name master

This happens when that particular agent host does not seem to have all the git branches.
Is there a specific agent property/setting that we need to enable that will ensure that any agent host will always have access to both the master and develop branches?

0
3 comments

Hi,

TeamCity only downloads what is needed for the build. If you need additional data, you should probably add it somehow on your own. There are several possibilities here:
-During the script, ensure that the branches you need are fully available locally.
-If you are using git merge-base, you might be able to do it against origin/master instead and not need to download the extra parts of the repository at all.
-If you want to merge, not just merge-base, you might consider using automatic merge: https://confluence.jetbrains.com/display/TCD10/Automatic+Merge

0
Avatar
Permanently deleted user

Hi Denis,

    Thanks for the reply.

You mentioned : During the script, ensure that the branches you need are fully available locally.

I want to know how we can ensure it.

As I said, we are still not clear as to why the git branch availability varies by agent host. 

Our understanding is that the agent git settings are derived based on that set in the Build Configuration. 

We cannot understand why here is a difference in the output on different agents when we list out the branches in our bash script using 'git branch -a'.

Is there some setting that we need to do within the build configuration?

 

 

0

I'll try to tackle your questions in a bit more detail.

Why git branch availability varies by agent: when you clone a repository, remote branches aren't set up locally, such as "develop" but "(remotes/)origin/develop". In order to have a copy of develop locally, you need to create your own "develop" branch and link it to origin/develop.

TeamCity won't copy all remote branches into local branches automatically, you will need to perform that manually via a script if you need to have multiple branches for a single build.

As mentioned, this isn't a TeamCity limitation, this is how git works. If you want to have all branches available, there are multiple possibilities:
-Download and create all branches in each agent. You can create a build configuration that does this through a script (git clone <repo>, git branch <branch> <remote_branch>, etc), then run the script in all compatible agents (you can do that via the custom run button)
-During your custom script, before merging (or merge-base-ing) run a git branch <branch_name> <remote_branch_name>
-Run merge-base directly over the remote instead of requiring a local copy. It should work just fine.

Hope this helps.

0

Please sign in to leave a comment.