要自动将更改从 bitbucket 存储库同步到 VSTS git 存储库,您可以使用VSTS 构建定义。详细步骤如下:
1. 使用 Bitbucket 存储库创建构建定义
创建 VSTS 构建定义时 -> 选择要同步的 Bitbucket 存储库 -> 创建。
2. 实现持续集成
在构建定义中 -> 触发器选项卡 -> 启用持续集成 -> 包含所有分支*
.
3. 使用脚本添加 PowerShell 任务以将 bitbucket 存储库与 VSTS git 存储库同步
使用以下脚本添加 PowerShell 任务:
if ( $(git remote) -contains 'vsts' )
{git remote rm vsts
echo 'remove remote vsts'
}
$branch="$(Build.SourceBranch)".replace("refs/heads/","")
git remote add vsts https://Personal%20Access%20Token:[email protected] /cdn-cgi/l/email-protection/project/_git/repo
git checkout $branch
git push vsts $branch -f
添加和配置PowerShell任务的详细步骤如下:
编辑您的构建定义 -> 单击+
为您的代理阶段添加任务 -> 搜索 powershell 任务 -> 单击添加 -> 单击您添加的 PowerShell 任务 -> 选择内联类型 -> 然后在脚本选项中添加您的 powershell 脚本 -> 保存构建定义。
现在,无论您的 bitbucket 存储库中更新了哪个分支,VSTS git 存储库都会自动同步。
同步从 VSTS git repo 到 bitbucket repo 的更改,您可以创建另一个 CI 构建来实现它。详细步骤如下:
1. 使用 VSTS git repo 创建 CI 构建
2. Enable continuous integration
3. Add a PowerShell task with below aspects
if ( $(git remote) -contains 'bitbucket' )
{git remote rm bitbucket
echo 'remove remote bitbucket'
}
git remote add bitbucket https://username:[email protected] /cdn-cgi/l/email-protection/username/repo.git
$branch="$(Build.SourceBranch)".replace("refs/heads/","")
git checkout $branch
git push bitbucket $branch -f