如何将bitbucket中的repo同步到Visual Studio团队服务?

DIG*_*JSS 2 bitbucket bitbucket-api azure-devops azure-pipelines azure-devops-rest-api

我是VSTS平台的新手.在我的一个项目中,我试图将bitbucket源代码控制集成到VSTS.通过这种方式,我应该能够看到bitbucket上的更新到VSTS帐户上.

我尝试过在VSTS上创建构建,但这只显示了所选的bitbucket存储库的提交历史记录.

有没有办法管理VSTS上的所有bitbucket更改作为源代码控制?

Mar*_*Liu 8

要自动将bitbucket repo中的更改同步到VSTS git repo,您​​可以使用VSTS构建定义来实现它.详细步骤如下:

1.使用Bitbucket repo创建构建定义

创建VSTS构建定义时 - >选择要同步的Bitbucket存储库 - >创建.

在此输入图像描述

2.启用持续集成

在构建定义 - >触发器选项卡 - >启用持续集成 - >包括所有分支*.

在此输入图像描述

3.使用脚本添加PowerShell任务,以将bitbucket repo与VSTS git repo同步

使用以下脚本添加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
Run Code Online (Sandbox Code Playgroud)

有关添加和配置PowerShell任务的详细步骤,如下所示:

编辑构建定义 - >单击+为代理阶段添加任务 - >搜索powershell任务 - >单击添加 - >单击您添加的PowerShell任务 - >选择内联类型 - >然后在脚本选项中添加您的powershell脚本 - >保存构建定义.

在此输入图像描述

在此输入图像描述

现在无论你的bitbucket repo中更新了哪个分支,VSTS git repo都会自动同步.


Yo同步从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
Run Code Online (Sandbox Code Playgroud)