1
votes

I have an open source repository in hosted in GitHub. I have connected that to the Visual Studio Team Services.

I want to work only through the Team Services (so, connect to my Team Services account and project in Visual Studio, not to GitHub). The GitHub repo should always reflect the latest version of the code pushed to VSTS.

The problem is it only works partially.

I managed to connect my GitHub repo to VSTS and Import the code.
I can see the initial commits made to the repo in GitHub.
I can see the build status for each of the commits in GitHub (green, red, orange).
I can trigger a build when I commit to code in GitHub.
I can connect, commit and trigger a build via Visual Studio.

However

I cannot see in VSTS the code and commits which were done in GitHub
I cannot see in GitHub the code and commits which were done in VSTS

So, it seems these are connected but out of sync.

I looked into this post here. It's 2 years old, so perhaps things have changed, because it does not work for me: How to synchronize VSTS and Github respositories when commits are made and also this Visual Studio Team Services - Sync w/ Github Repository

The thing I don't get is that when a build is triggered, it pulls the latest sources, and I can see my last commit description, but the file is not updated in VSTS. enter image description here

Regardless, I then do the steps described in the anwser, but it keeps saying 'Already up-to-date'. This sync build succeeds but nothing changes - neither in VSTS nor in GitHub.

enter image description here

What do I need to do to have them both in sync?

2

2 Answers

2
votes

You just need two CI builds to sync GitHub repo with VSTS git repo. And if your GitHub repo and VSTS git repo are not synced, please sync first, and then add below settings for future sync automatically.

I cannot see in VSTS the code and commits which were done in GitHub

To solve this problem, you just need a CI build definition for GitHub repo seems you already have) which can be automatically triggered when new changes are pushed to GitHub repo.

In the GitHub CI build definition, add a PowerShell task to push new changes from Github repo to VSTS git repo. The PowerShell script as below:

git checkout $(Build.SourceBranchName)
git remote add vsts https://Personal%20Access%20Token:[email protected]/project/_git/repo
git push vsts $(Build.SourceBranchName)

Note:

  • The CI build should be specified with any branches in the GitHub repo. So you can specify * for Branch filters.

    enter image description here

  • For the PowerShell task, you should deselect Fail on Standard Error option.

    enter image description here

I cannot see in GitHub the code and commits which were done in VSTS

To solve this problem, you need another CI build definition for VSTS git repo so that after new changes pushed to VSTS git repo, build will be triggered automatically.

And you can push the changes from VSTS git repo to GitHub repo by PowerShell task:

git checkout $(Build.SourceBranchName)
git remote add github https://username:[email protected]/username/repo
git push github $(Build.SourceBranchName)

Note: you should also specify the Branch filters with * to match all branches of the VSTS git repo. And it's also need to deselect Fail on Standard Error option for PowerShell task.

1
votes

As far as I can tell from the screenshots you're providing, you're not doing anything with your VSTS repository. The repo you're syncing is from GitHub. The repo that you're pushing to and pulling from is also GitHub.

If you don't clone or otherwise interact with your VSTS repository, it's not surprising that you're not seeing anything happening. You want your build to use the VSTS repository as its source. Then the commands you're running in the build will pull the latest changes from GitHub, and push the latest changes from VSTS.