如何将 bitbucket 中的 repo 同步到 Visual Studio 团队服务? [英] How to sync repo in bitbucket to Visual studio team service?

查看:26
本文介绍了如何将 bitbucket 中的 repo 同步到 Visual Studio 团队服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am very new to VSTS platform. In one of my project, I am trying to integrate the bitbucket source control to VSTS. By this way I should be able to see the updates made on bitbucket onto the VSTS account.

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

I have tried creating build on VSTS, but that only shows the commits history of the selected repository of bitbucket.

有没有办法将 VSTS 上的所有 bitbucket 更改作为源代码管理进行管理?

Is there a way to manage all the bitbucket changes on VSTS as source control?

推荐答案

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

To sync changes from bitbucket repo to VSTS git repo automatically, you can achieve it by using a VSTS build definition. Detail steps as below:

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

When creating a VSTS build definition -> Select the Bitbucket repo you want to sync -> create.

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

In the build definition -> Triggers Tab -> Enable continuous integration -> Include all branches with *.

使用以下脚本添加 PowerShell 任务:

Add a PowerShell task with below script:

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任务的详细步骤如下:

For the detail steps to add and config the PowerShell task as below:

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

Edit your build definition -> Click + to add a task for your agent phase -> Search powershell task -> click Add -> click the PowerShell task you added -> select Inline type -> then add your powershell script in the Script option -> Save build definition.

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

Now no matter which branch is updated in your bitbucket repo, VSTS git repo will be synced automatically.

您可以将 VSTS git repo 的更改同步到 bitbucket repo,您​​可以创建另一个 CI 构建来实现它.详细步骤如下:

Yo sync changes from VSTS git repo to bitbucket repo, you can create another CI build to achieve it. Detail steps as below:

2. 启用持续集成3.添加一个PowerShell任务,有以下几个方面

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:password@bitbucket.org/username/repo.git 
$branch="$(Build.SourceBranch)".replace("refs/heads/","")
git checkout $branch
git push bitbucket $branch -f

这篇关于如何将 bitbucket 中的 repo 同步到 Visual Studio 团队服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆