0

As the title indicates, I have an issue making a build step in VSTS / Azure DevOps, where I would like to update an external git repo when I push to ie. my realease or master branch. I've tried several add ons from the marketplace, but none of them seems to fit my needs. I have a few prerequisites:

  • My external git is behind port 33
  • My external git only accepts SSH keys as authentication so I need to store an SSH private key somewhere to be able to push to the external source.

I have alternatively also tried Gitlab because of the built in mirroring feature, but unfortunately that won't accept port 33, only 22 and other standard ports :-(

Thank you so much in advance!

phpNoobish
  • 111
  • 1
  • 12

1 Answers1

0

You could add a PowerShell Build Step with a Condition if the 'Build.SourceBranch' matches 'master' or 'release', and then the PowerShell script being something like this example. This pushes everything in one go, not each commit. This can also catch up a repo that is behind.

# Test to see if remote alias already exists
git ls-remote ssh://user@host:1234/srv/git/TargetRepoSameName
# Add a remote alias
git remote add any_name_123 ssh://user@host:1234/srv/git/TargetRepoSameName

# push local repo to 'any_name_123'
git push any_name_123 --all
# optional: delete all tags before attempting to push local tags
git push any_name_123 --delete `$(git tag -l)
# push local tags to remote repo 
git push any_name_123 --tags

Notice that I'm using port # 1234, whereas if you do not specify a port, then 22 is the default. Please use this snippet in your overall solution. You could also use a git-hook to push changes.

Antebios
  • 1,681
  • 1
  • 13
  • 22
  • Looks promising.. I still need to add a ssh key as well - any suggestions on how to do that? sorry, but I am very new to all this :-( – phpNoobish Jan 21 '19 at 15:23
  • Do something like this: https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=vsts Just add ssh credentials like any other git repository. – Antebios Jan 22 '19 at 21:28
  • I have added the "Install a SSH Key" step as a build step, but I can't seem to figure out how to use it afterwards.. Can you guide me ? see screenshots: https://jmp.sh/hDMqYvh – phpNoobish Jan 23 '19 at 10:52