需求
在之前的文章中“[DevOps]如何用VSTS持续集成到Github仓库”
我们有讲述如何将vsts中的代码编译推送到github中,这一篇我们来完善,如果有人给你开源项目推送了代码,你审核后,如何自动将代码推送回vsts,从而实现双同步。
准备工作
首先你要生成一个key,登录到你的vsts中。进入“Security”菜单栏。

生成密钥
点击Add,添加一个密钥。

image.png
注意:此处生成的密钥,请自行保存,因为你刷新页面后,此处的密钥就不会再出现。同时密钥是有失效时间的。所以请注意。
创建一个任务
回到我们的“Build and Release”菜单栏,创建一个新的task。

image.png
点击新增“Empty process”取个名字叫做“SyncFromGithub”,选择队列为“Host”,

image.png
然后选择获取代码源,然后进行github授权,选择你对应的仓库。

image.png
回到Phase,新增一个cmd,命令行

image.png

命令行.png
在第一个命令行中填入以下代码。其中$(vststoken)为参数名称,我们待会儿说。
pull https://$(vststoken)@52ABP.visualstudio.com/_git/52ABP.School master
我们先拉取下vsts中仓库的代码。

image.png
然后再添加一个命令行工具。
push https://$(vststoken)@52ABP.visualstudio.com/_git/52ABP.School head:master
然后再将代码推送到服务vsts中。
参数的设置
我们之前要的token值,用于授权验证,打开“Variables”菜单栏,
新建一个vststoken的名称。将刚刚生成的token值,输入到value中。

image.png
如上图,加锁后。会启用掩码。这样的话就安全不少。
设置触发器
然后就跟之前的课程一样,设置下触发器。

image.png
到options中启用标记,如下图

image.png
生成任务规则
$(BuildDefinitionName)$(SourceBranchName)$(Date:yyyyMMdd)$(Rev:.r)
最后,右上角保存并添加到队列中即可。
END
最后的结果就是这样!

image.png
GitHub仓库:https://github.com/52ABP/52ABP.School
视频课程
最近我录制的.net core 入门已经发布有兴趣的可以去了解。
https://mp.weixin.qq.com/s/riPvwXpKe5LuPu0hQfXS9A