Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Commit file back to repository from build server in Visual Studio Team Services

I'm currently setting up continuous integration using TFS/Visual Studio Team Services (was VS Online), and I'm using the Team Foundation Build 2015 tasks. So not the XAML builds.

I'm using it to build a Xamarin Android project, but that's pretty irreverent I guess,

The process should be like this:

  • After a check-in:
  • TFS should download the sources
  • TFS should increment the version number within AndroidManifest.xml
    • I've managed to do this by making a PowerShell script for this.
  • After the AndroidManifest.xml file is modified, it should be committed back into the TFS repository

Then the rest, build deploy into hockeyapp etc

The first steps are all configured, but I'm struggling with the commit part. How do I get TFS to commit the file? I don't really see any task suitable for it. I've tried using the Copy and Publish Build Artifacts Utility - But that did not seem to work, and I'm not even sure if that's the right utility

I'm using the default hosted build agent btw. Any help would be appreciated

like image 200
Ron Sijm Avatar asked Apr 15 '16 11:04

Ron Sijm


People also ask

How do I commit changes to github from Visual Studio?

Just enter your commit message and then select Commit All. The equivalent command for this action is git commit -a . Visual Studio also makes it easy to commit and sync with one click by using the Commit All and Push and Commit All and Sync shortcuts.

How do you commit staged changes in Visual Studio?

When you stage a change, Visual Studio creates a Staged Changes section. Only changes in the Staged Changes section are added to the next commit, which you can do by selecting Commit Staged. The equivalent command for this action is git commit -m "Your commit message" .

How do I commit code from Azure DevOps to Visual Studio?

Open the repo within Visual Studio Code when prompted to do so (after cloning the repo in the previous objective). Make changes to the README.md file. Commit the changes locally with a comment. Push/sync the changes to Azure DevOps.


1 Answers

Warning

I do want to point out that checking in changes as part of the build can lead to some features of VSTS/TFS not working. Association of work items to the checkin, sources and symbol generation, tractability from changes to build to release and integration with Test Manager, remote debugging, will likely not yield the expected results because the Changeset/commit recorded in te build may not match the actual sources. This may lead to unexpected funny behavior.

Also, if any new changes have already been committed/checked-in after the build has started, the version number may be updated in Source Control for code that was not actually released under that version.

So: First of all, it's considered a bad practice to change the sources from the build process.

Alternatives

There are better ways of doing it, one is to use the build version (Build_BuildNumber or Build_BuildID variables). Alternatively you an use a task like GitVersion to generate the semantic version based on the branch and tag in your git repository. That way your build will generate the correct version number and will increment the revision in case the same sources are built multiple times.

I understand, but I still want to check in my code as part of the build

If these things don't work for you and you still want to check in the changes as part of the build, you can either use the TFVC Build Tasks if you're using TFVC or use the Git Build Tools to add the remote to the local repository and then use the git commandline tools to commit and push the changes back to the repository.

These extensions require TFS Update 2 to install. But you can push the individual build tasks using the tfx commandlien tool. For the TFVC tasks the process is explained here.

On mac

On the mac it's going to be harder since you're using TFVC. My TFVC tasks leverage the TFS Client Object Model and Powershell to communicate to the TFS Server. The tf.exe tool doesn't even work on windows when you're in the context of a build, which is why I need to call into the VersionControlServer object directly. Given I'm dependent on these technologies, the tasks won't run on a Mac or Linux agent.

You could try to see whether the Team explorer Everywhere X-platform commandline works from the build agent (using a shell script). I have no way to test this on an actual Mac.

Given the cross platform nature of your project I'd recommend to move to Git, it integrates into XCode and Android Studio, making it easier to do a native UI or build on top of native libraries.

Alternative 2

You could setup a build which does the required changes to the code and then checks in the modified code. Then have a (CI) build run the Android and the Mac builds using the modified code.

like image 159
jessehouwing Avatar answered Oct 29 '22 18:10

jessehouwing