4

I have an issue with Team City 8.0.3 (build 27540) hanging on a secondary build step that pushes changes to a remote repository. I can't locate any information that gives me insight into what's wrong.

The VCS is setup via SSH, using the default private key, and checkout mode is set to automatically on agent.

Source is checked into a "repositoryPath" via a checkout rule.

Build step runs git commands from the working directory of "repositoryPath".

Here is the build log from the second step that runs the commit:

Step 2/2: Commit dlls (Command Line) (running for 1m:09s)
[16:46:51][Step 2/2] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script5045114249582743499.cmd
[16:46:51][Step 2/2] in directory: C:\TeamCity\buildAgent\work\8df15579b05cdb68\repositoryPath
[16:46:51][Step 2/2] [master 9fa24ba] Teamcity update
[16:46:51][Step 2/2]  1 file changed, 0 insertions(+), 0 deletions(-)
*** HANGS HERE ***

Here is the git push command line step:

"%env.TEAMCITY_GIT_PATH%" add .
"%env.TEAMCITY_GIT_PATH%" commit -m "Teamcity update"
"%env.TEAMCITY_GIT_PATH%" push

If I drop to the the Team City work directory, I notice that the commit has taken, but hasn't been pushed. If I attempt a git push, it goes off without any problem.

I would be happy to furnish further detail if it would help.

Jeff Mitchell
  • 1,459
  • 1
  • 17
  • 33

3 Answers3

6

TeamCity uses cmd.exe to run your git commands. As this stackoverflow answer says, Git relies on the shell scripting, which is not available inside cmd.

Try to call msysgit's bash to execute a bash script with required git commands.

Community
  • 1
  • 1
Nikita Skvortsov
  • 4,768
  • 24
  • 37
  • Thank you Nikita, that was the problem. It makes sense when I think about it, but the other git commands running successfully threw me off. – Jeff Mitchell Aug 23 '13 at 13:59
  • hi nikita. can you provide the exact command because it didnt work for me. thx – Mantzas Sep 29 '13 at 18:20
  • 1
    @Mantzas, it should look like this (just as an example, I do not have an opportunity to check it right now): `"C:\Program Files (x86)\Git\bin\bash.exe" -c "git add .; git commit -m 'blah-blah-blah'; git push"` – Nikita Skvortsov Sep 30 '13 at 11:39
  • 1
    @nikita, i am getting a "git command not found error". seems like the environment is not set up? – Mantzas Oct 01 '13 at 17:37
  • 1
    @Mantzas exactly. To investigate the environment you could use following command in command line runner: `"C:\Program Files (x86)\Git\bin\bash.exe" -c "echo $PATH"` – Nikita Skvortsov Oct 02 '13 at 10:45
  • 3
    @nikita: i finaly found what was wrong. Push to my remote repository asked for a password which is not reported and gives the illusion of a hanging push. after providing with a password in https format all went well. I can now push now directly from command line without the bash shell. Thanks anyways. – Mantzas Oct 03 '13 at 15:18
  • @Mantzas hi i know this is too old, but i have the same problem could you tell me how did you provide the password i have used the wincred for the credentials but still its stuck – goldsmit409 Apr 22 '15 at 09:30
  • 1
    @goldsmit409 if you are using a http/s git call you can provide the username and the password to it. if that does not work then use https://gitcredentialstore.codeplex.com/ install and use it to save the password for your repository on your build machine. hope this helps – Mantzas Apr 22 '15 at 13:06
  • @Mantzas, I would suggest you extract these findings into an answer. I had exactly the same problem, and only thorough reading through your comments gave me a hint. I solved it with the help of gitcredentialstore, as you suggested. – Yan Sklyarenko Jun 10 '15 at 08:53
  • @YanSklyarenko i would but the answer is already accepted which means that the original issue is resolved with the accepted answer. It seems that my solution handles another kind of build hang. Happy to help out. – Mantzas Jun 10 '15 at 16:27
2

As a comment above also suggests, the root cause is probably git asking for a password, which is never supplied by TeamCity.

Try configuring git so that it doesn't request a password (e.g. setup ssh keys/use wincred/git-credential-winstore).

Or if you're using GitHub and are are happy to put your password in the url (as suggested by this post):

git push https://username:password@github.com/username/repository.git
Community
  • 1
  • 1
Andy Joiner
  • 5,932
  • 3
  • 45
  • 72
1

I had this problem, but as I was using SSH I couldn't specify the username and password in the command. I knew the build was hanging because it was waiting for a user prompt.

I noticed that even though I had a HOME system environment variable set to where the .ssh folder was, it was not present in the SET list when TeamCity ran the git push command.

Consequently I changed the script to reset the HOME variable:

SET HOME=D:\
git push

...where D:\ is where the .ssh folder is containing the public/private keys.

n4cer500
  • 743
  • 1
  • 8
  • 21