How can I setup credentials for git push on Teamcity's PowerShell build step?
I have been trying to git push some changes on the local branch of an agent to a remote branch on a PowerShell build step. A post from this link https://teamcity-support.jetbrains.com/hc/en-us/community/posts/206151989-How-to-push-changes-back-to-source-repo-in-git says that I need to store credentials in its Git credential manager.
I have tried to use "git config" to set email password but it still didn't work. I also don't know how to use the command "git credential". My script is below, the build got stuck at the git push line:
git config --global user.email %git_username%
git config --global user.password %git_password%
git config --global credential.helper store
git remote add origin2 %client_git_url%
git push origin2 %local_branch%:main
Thanks!
Please sign in to leave a comment.
May I suggest to consider using SSH Agent feature (https://www.jetbrains.com/help/teamcity/ssh-agent.html)? It allows you to use an uploaded SSH key so that it would be automatically downloaded to the agent at the start of build and removed after the build is over. Since the SSH key would be available locally it could be used to automatically authenticate your `push` command.
I recommend it because this way you do not store your sensitive data on the agent machine which is more secure.