Bamboo fails to push tags to Git repo
Asked by Config Manager:

I am using Bamboo 5.2 to build and test solutions stored in Git and managed by Stash 2.8  

At the end of a build I want to create a Git tag and push it back to the Stash-managed repo. There appears to be no built-in support for this for Git, just for SVN - is this to be provided in a future release?  

Lacking this, I have created an inline script which issues a number of commands  

cd ${bamboo.build.working.directory}\\solution  
"C:\\Program Files (x86)\\Git\\bin\\git.exe" tag "${bamboo.buildKey}_${bamboo.buildNumber}"  
"C:\\Program Files (x86)\\Git\\bin\\git.exe" remote add origin ssh://git@ip_addr:7999/project/solution.git  
"C:\\Program Files (x86)\\Git\\bin\\git.exe" push --tags origin  

The "tag" and "remote" commands execute but the push hangs, resulting in the build hanging and no log file (presumably buffered in memory and lost on stopping the build). If I type these exact commands in a bash or command window as the same user as that running the build agent, they work.  
I googled for help and found <https://confluence.atlassian.com/display/BAMKB/Merging+and+pushing+to+remote+repository+fails>which suggests a work around but I couldn't get it to work either.  

I also note that a similar question at [https://answers.atlassian.com/questions/215482/bamboo-failing-to-git-push-changes](/questions/215482/bamboo-failing-to-git-push-changes) has gone unanswered...  

What am I missing?


Answers:
author: Config Manager
body: Thanks for the advice. I've tried the relatively unsecure http with password as Charles suggests and it has worked. i.e.

"C:\\Program Files (x86)\\Git\\bin\\git.exe" push --tags <http://user:password@ip_addr:7990/scm/project/solution.git>

I had tried disabling shallow clones as comments elsewhere on the internet suggested that there may be problems - this is why I had defined the remote as not being a full clone meant that it was not set up by default. But it made no difference.

I will now re-experiment with SSH, and try the Cygwin version as well. If I have to leave it like this then this won't really be a problem as we have a standard build user account with password that most people know and so the security risk is low.

I'll leave off accepting until I've looked into this a bit more (tomorrow) and post an update.


author: Marco_Wlotzka
body: We're using bamboo on windows and checkout via https there. This is my solution:

Create _netrc file under bamboo service user account home.

```
git.mycompany.comlogin usernamepassword password
```

Source: <http://stackoverflow.com/questions/6031214/git-how-to-use-netrc-file-on-windows-to-save-user-and-password>

Then, create a script task with following content to change remote url right after checkout

git remote set-url origin ${bamboo.repository.git.repositoryUrl}

And don't forget to set the git user:

```
$ git config --global user.name "bamboobuild"$ git config --global user.email bamboobuild@mycompany.com
```

```
?
```

The log:

```
build	08-Oct-2014 09:45:49	GitTag:build	08-Oct-2014 09:45:49	  Read C:\b\SA-ICG0-JOB1\tagversion.txtbuild	08-Oct-2014 09:45:49	  git tag -a "v1.2.1" -m "Release from master tagged with v1.2.1!" -m"***NO_CI***"build	08-Oct-2014 09:45:49	  git push origin "v1.2.1"build	08-Oct-2014 09:45:51	  To https://git.mycompany.com/team/foobar.gitbuild	08-Oct-2014 09:45:51	   * [new tag]         v1.2.1 -> v1.2.1
```

<br />


author: Sean Wolf
body: The authenticity of the host was not verified.. git was asking you to type 'yes' or 'no'


author: Rajendra Talluri
body: Hi

In mycase i am trying to push the jar generated back to Git.

So i have created and inline script with

git init

git add myjar and

Tried wit the http://user:pwd@github.com/myrepo.git

but this was not worked any idea or sugession please


author: Przemek Bruski
body: Try redirecting the input to git from NUL like "git whatever \<NUL" - maybe there's some interactive input required?

Also if you're using SSH distributed with Git, it's horrible - try using the one from Cygwin, it's approximately 10 times faster (also more stable).


author: cofarrell
body: Hi,

The hanging is very strange. Do you have any kind of passphrase on the SSH key? As an experiment you could try use the HTTP URL (and hard code the username/password). If that works it's probably something to do with SSH.

You might want to disable 'shallow clones', it's an option under 'advanced' and I believe it's the default. I don't see how that would cause the hanging, but it's worth a shot.

I'm afraid I work on Stash and I couldn't say if Git will be added to the VCS Tagging plugin in future.

Cheers,  
Charles


Tags: bitbucket-server

git