How to push changes back to source repo in git

Answered

I curious how one can push changes back to the git source repo.

Basically, the build changes a few source files which then need to be push backed to the source repo in git.

16 comments

TeamCity does not provide a feature like that.
You can use agent-side checkout and then use command line VCS tools to perform the VCS operations within the build just like you would do in a command prompt on a local machine.
Depending on the changes, it might be good to revert the working copy to the state corresponding to the build start as TeamCity assumes no VCS changes are made during the build.

0

Thanks for the reply. Apologies for getting back so late.

I thought TC's auto merge feature was implemented for this scenario.

Is that true?

0

TeamCity automatic merge feature allows to merge a branch into another branch after successful build. This does not include ability for a build to change files before the merge occurrs.
However, if you rework your process to push the modified files into a branch, TeamCity can then be confiured to build and merge the changes on success.

0

Very good. Thank you for the answer. It helps quite a bit. God bless.

0

One more question, I am getting the following error when use a git push script during a commandline build step.

Any thoughts on this one?

Starting: E:\TeamCity\Temp\agentTmp\custom_script34180244.cmd
in directory: E:\TeamCity\Work\
\Git\bin\git.exe was unexpected at this time.
Process exited with code 255
Step Update Source (Command Line) failed
0

Seems like an error in the script you specified. One of the most common issues is not wrapping paths with space with quotes.

If you need more guidance on this, please include your current script.

0

Hi. I just saw this, it's exactly what I need to do, I've tried many different ways but I always get errors when trying to push back.

Is this included in the latest teamcity or if not can you help with a workaround?

Thank you.

0

Hi Ricardo,

 

There were several issue in this thread, please describe the one you have in detail.

0

Basically I want to use git to push back to origin within a build step. Been having authentication issues or can't find the repo, etc

0

Ricardo,

So as I mentioned in my first reply you should use agent-side checkout and then call git commands from within a build step (just like you would do from a command line). TeamCity does not seem to blame here and you just need to figure out due git command.

Depending on the VS root settings used it might be not possible to reuse repository authentication, so you probably should supply authentication anew to the git command.

0

I'm using HTTPS auth and I kept getting these types of errors:

[11:18:49][Step 1/1] bash: /dev/tty: No such device or address
[11:18:49][Step 1/1] error: failed to execute prompt script (exit code 1)

 

When using git directly on the agent in the command line it works, same exact commands, so it's definitely TeamCity related.

0

Ricardo, I still believe this is more related to the environment/generic OS logic and not exactly TeamCity-introduced behavior.

Please check the related topic from our documentation to try to resolve your "script works differently" case.

0

Hi.
I'm already using a regular user and everything I execute with that user works - just not under the TeamCity build. So I have tried a few things to try to make it work - nothing except executing the same exact thing while logged into the machine, worked.

I'll have a look at the other suggestions and let you know.

0

Yegor, could you please elaborate on this comment
"Depending on the VS root settings used it might be not possible to reuse repository authentication, so you probably should supply authentication anew to the git command."

What VCS root setting will enable / disable reusing the repo auth?

I always get "fatal: could not read Password for 'https://user@github-enterprise.company.com': No such device or address'

when I try to do git push from teamcity commandline runner

 

thx

Scott

0

Hi Scott,

I guess what you experience is related not to TeamCity per se, but to the headless execution of the process and Git client specifics.

On the Git authentication: "Default private key" is not much related to TeamCity as it depends on the ssh key saved as default for the OS user. Username/password should also be possible to feed to the git client, e.g. via git-credential ( https://git-scm.com/docs/git-credential ).

0

Please sign in to leave a comment.