要自动将 bitbucket repo 的更改同步到 VSTS git repo,您可以使用 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:PAT@account.visualstudio.com/project/_git/repo
git checkout $branch
git push vsts $branch -f
添加和配置PowerShell任务的详细步骤如下:
编辑您的构建定义->单击+为您的代理阶段添加任务->搜索powershell任务->单击添加->单击您添加的PowerShell任务->选择内联类型->然后添加您的powershell脚本在脚本选项中 -> 保存构建定义。
现在无论你的 bitbucket repo 中哪个分支更新,VSTS git repo 都会自动同步。
从 VSTS git repo 到 bitbucket repo 同步更改,您可以创建另一个 CI 构建来实现它。详细步骤如下:
1。使用 VSTS git repo 创建 CI 构建
2. 实现持续集成
3. 添加一个PowerShell任务,包含以下几个方面
if ( $(git remote) -contains 'bitbucket' )
{git remote rm bitbucket
echo 'remove remote bitbucket'
}
git remote add bitbucket https://username:password@bitbucket.org/username/repo.git
$branch="$(Build.SourceBranch)".replace("refs/heads/","")
git checkout $branch
git push bitbucket $branch -f