Showing posts with label TFS2012. Show all posts
Showing posts with label TFS2012. Show all posts

Thursday, 16 May 2013

Continuous Integration - TFS Build web deploy

I have been working on web development for a while no wand using TFS 2010 and 2012.
For a while I am using "web deployment" functionality.

In this article I make the assumption that:
  1. You know how to setup TFS build.
  2. You have setup MS Deploy on your IIS application.
  3. Your are using IIS 7 or higher

To create next step in CI is to have build server deploy your latest version of code to the website.

I am using default build template for this deployment.

Make sure that Web deploy is installed on the server (TFS and deployment)
Note: I am using version Web Deploy 3.0




From the picture you can see default build configuration.

I am using MSBuild arguments in order to realize my deployment.

Now the arguments you need to provide to be able to create deployment.
 
/p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:MSDeployPublishMethod=InProc /p:CreatePackageOnPublish=True /p:MSDeployServiceUrl=localhost /p:DeployIisAppPath="Your Project App Name" /p:UserName=domain\user /p:Password=userPassword

I have had few attempts to do this right, but the most important issue I have had is:
  1. Too long output drop folder in build configuration ( file path exceeded 248 characters)
  2. Insufficient write permissions. This was due to account that is running build did not had write access to folder. Do not let it fool you, account that does the publishing has to have access rights to write into the folder.  Alternative is web deploy service has to run under account that has write privilege to write into target folder. 





Friday, 15 February 2013

TFS build using testing files

TFS build using testing files

Desired result

I want to run test that are using test files on server.
I am targeting VS and TFS 2012

Solution

My test solution layout.


Add all your files into folder which is part of your solution.
Set property all files you need for tests to content and copy always.
This will ensure that files are always the latest ones.




Now create test class

    [TestClass]
    [DeploymentItem(@"TestData", @"TestData")]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Assert.IsTrue(File.Exists(@"TestData\TextFile1.txt"));
        }
    }

and test result

You need to use in, out directory for Deployment Item, this will copy only existing item from your solution. I have not managed to create only empty directory.

Check if your directory has been created in location: ClassLibrary1.Tests\bin\Debug.

You can read up about DeploymentItem


Monday, 11 February 2013

Changing build agent working directory

Changing build agent working directory


default location after installation is:


Working directory
$(SystemDrive)\Builds\$(BuildAgentId)\$(BuildDefinitionPath)

It is desirable to move this location as the builds will add up and it will be taking a lot of space in you system drive. This is useful too if you have multiple builds and you want to retain build history.


If you had already run any build you will have to move existing folder, as results to your builds are in that directory.


When you have moved the build folder make sure that you check permissions on the build directory.

Wednesday, 12 September 2012

TFS select work items for project


Yesterday, I needed to connect to get all work items for project in Team Foundation 
Server. I have seen couple guides, but not easy to find.  
 
 
 
Here is how to get WorkItems Collection: 
 
This is example code and is not fit to be implemented as it is. 
 

 
protected WorkItemCollection ConnectToTFS()
{
 WorkItemCollection workItemCollection = null; 
 try
 {
  // lets define location of tfs server
  var tfsServerUri = new Uri("http://localhost:8080/tfs");
 
  // Account definition
  // var password = "password";
  // var domain = "domain";
  // var userName = "user";
var projectName ="TfsQueryProject";
  Project project = null;  
 
  // needed if you access tfs as user
  // NetworkCredential account = new NetworkCredential(userName, password,domain)
// TeamFoundationServer server = new TeamFoundationServer(tfsServerUri , account);

 
  TeamFoundationServer server = new TeamFoundationServer(tfsServerUri );

  // make sure you can
  server.Authenticate();
 
  // Get access to work items collection for server.
  WorkItemStore store = new WorkItemStore(server); 
 
  // get existing project 
  project = store.Projects[projectName]; 
 
  if (project == null)
   throw new Exception("Project could not found"); 
 
  // now construct query for work items that are in project 
  string querySql = "SELECT [System.Id], [System.Title], [System.Description] " +
     "FROM WorkItems " +
     "WHERE [System.TeamProject] = '" + PROJECT + "' " +; 
 
 //Execute query to get collection with have all the workitems from the project specified. 
 workItemCollection = store.Query(querySql); 
 
 

 }
 catch (Exception ex)
 { 
   // Todo:  handle exception as required.
throw ex;
 }
 
return workItemCollection; 
}