简体   繁体   English

在VSTS / Azure DevOps中推送时将构建定义镜像存储库镜像到外部git存储库

[英]Build definition mirroring repo to external git repo on push in VSTS / Azure DevOps

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. 如标题所示,我在VSTS / Azure DevOps中进行构建时遇到了一个问题,当我推送到ie时,我想在其中更新外部git repo。 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 我的外部git在端口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. 我的外部git只接受SSH密钥作为身份验证,因此我需要将SSH私钥存储在某个地方,以便能够推送到外部源。

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 :-( 由于内置的​​镜像功能,我也尝试了Gitlab,但不幸的是,它不接受端口33,仅接受22和其他标准端口:-(

Thank you so much in advance! 提前非常感谢您!

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. 如果“ Build.SourceBranch”与“ master”或“ release”相匹配,则可以添加带有条件的PowerShell构建步骤,然后PowerShell脚本类似于此示例。 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. 请注意,我正在使用端口号1234,而如果未指定端口,则默认为22。 Please use this snippet in your overall solution. 请在您的整体解决方案中使用此代码段。 You could also use a git-hook to push changes. 您还可以使用git-hook推送更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM