Execute powershell code during a build in TFS 2015 Update 2

In TFS 2015 build system, running a PowerShell script stored in source code is simple because there is a dedicated action to accomplish this task, but if you want to run a PowerShell script that is not in source control, you have no option out of the Box.

Thanks to Update 2, you have now the ability to use the extensions you can find on Visual Studio Marketplace directly in your on-premise TFS installation. In the Upper Right corner of Web Ui you can find an icon that link to

This image shows the link in TFS UI to open the control panel to manage extension.

Figure 1: Link to manage extensions

This opens an administration page that allows you to manage extensions of your TFS installation. The first time you open this page, you will see no extension installed, so it is time to browse Visual Studio MarketPlace to find an extension. Actually I want to run inline PowerShell and I can immediately find that there is an extension that can solve my need.

As you can see from Figure 2, this extension have a couple of button, the first one, Install, is used to install this extension on one of your VSTS account, but if the extension is compatible with on-premise TFS you have also the option to Download the extension.

This image shows that extensions can be downloaded to local pc to be installed to TFS

Figure 2: Once you find an extension compatible with on-premise TFS you can download it.

The extension is a simple .vsix file, and from extension administration page you can upload to your TFS.

This image shows how you can upload downloaded extension to your TFS instance.

Figure 3: Once downloaded you can upload the extension to your TFS.

The process of uploading is really simple:

This image shows how you can choose the file to upload

Figure 4: Browse for downloaded extension

Tfs shows info for file to upload

Figure 5: Upload UI shows all the detail of the file

Now you can press Upload button, and the extension is uploaded to TFS and ready to be activated.

TFS shows the list of uploaded and installed extensions

Figure 6: Uploaded extension is now listed in the list of available extension

For each extension TFS ask you to install in specific project collection

  1. Figure 7: Install the extension on one or more collection

The concept behind “install then activate” is that, once uploaded the extension is available for the TFS Server instance, but then you should install in each Project Collection where you want to use that extension.

TFS asks you to choose the collection where you want to use the extension.

Figure 8: Choose the collection you want to install the extension into

Once you choose the Project Collection you need to confirm the operation

Figure 9: Confirm the selection

Once the Extension is installed in one Project Collection it can be used. In this example the extension contains a new build Task that allows you to execute an arbitrary PowerShell script during the build. To verify that everything is ok you can create a build and verify that the new Task is available and ready to use.

the extension is used in a build, where I was able to add the new task that executes arbitrary powershell code

Figure 10: The extension is ready and can be used

Thanks to TFS 2015 Update 2 you can Download and install extension for VSTS Marketplace to your on-premise TFS installation with few clicks.

Gian Maria.

Add Reporting to an existing Team Project

In previous post I demonstrated how you can create a Team Project from Web Interface thanks to TFS 2015 Update 2. The only drawback of this approach is that no Sharepoint Site and no Reporting Services portal are created.

While SharePoint integration is now an uncommon requirement, reporting services are still used. After my new Team Project (namedTest Project 2 ) was created from web interface, I verified that nothing gets created in my Reporting Services instance.

image

Figure 1: No reporting was created for new Team Project

Thanks to TFS Power Tools you are able to create both SharePoint portal and Reporting services for an existing project.

You can add reporiting with the tfpt.exe power tools command line utility. As an example here is the help for the addprojectreports command, used to create reports for an already created Team Project.

This image shows the list of options available to the addprojectreports command.

Figure 2: Help of the addprojectreports command

This is the exact command line I need to recreate reports for my Team Project is:

tfpt addprojectreports 
	/collection:http://tfs.cyberpunk.local:8080/tfs/ExperimentalCollection 
	/teamproject:"Test Project 2"
 	/processTemplate:"CMMI"

After a little while tfpf.exe created everything as I can verify from Reporting Services Site, now I have the usual folder for the Team Project that contains all Reports.

After tfpf addprojectreports command all reports for the team project are correctly created in Reporting Services Site

Figure 3: Reports were created for the Team Project

The same can be done with SharePoint portal. Thanks to Power Tools you can create the Team Project directly from the Web Site and add portal or reports subsequently and only if you need them.

Gian Maria.

TFS 2015 Update 2 is released

You can find all the details directly in Visual Studio Site, but I want to emphasize that TFS and VS Updates are much more than Service Packs, because they also intrdoduce a lot of new features. Here is a list of my personal favorites features of TFS Update 2

Introduction of new Release Management System

New release management system is completely Web and does not require separate client to download, but this is not the only advantage. This update introduces the ability to integrate with VMWare, and have a new extension to connect to System Center Virtual Machine Manager.

Delete of work item from the UI

This solves probably the most common question I got during TFS Courses. Basically every attendee asks “how can I delete Work Item?”. The usual answer is, you need to resort to Command Line utility, because deleting a Work Item actually deletes its history from database and its a dangerous operation to do.

This is not always true, there are lots of legitimate reasons to delete a Work Item and now it is possible to delete Work Items directly from the Web Interface. Deletion actually move Work Items to a Recycle Bin where you could still restore deleted Work Items or delete permanently.

Extension from marketplace

This is another really cool feature, Marketplace was available until now, only for VSTS accounts, but now you can add extensions even to your TFS on premise instance.

Gated Check-in for new build system

This was another great stopper for customer to adopt the new build system, until Update 2 the new build system has no support for Gated Check-in. With Update 2 you can create a Gated Check-in TFVC vNext build

New Link from Git Code and Work Items

Now you can link a work item not only to a Commit in Git but also to an entire branch. This is really interesting if you work with GitFlow and are used to feature branches. With this approach you can link each PBI or User Story directly to Git Feature branch that is implementing it.

This is especially useful for Scrum Team, because you can create a pull-request for all Completed User Stories of the Sprint, and do a review. Then, during Sprint Review, you can complete pull requests only for those User Stories that are considered completed by the Product Owner. All the User Stories that are still not considered completed will flow to the Next Sprint, postponing the Merge.

I strongly encourage you to have a look at the full list of the new feature, and, as always, I strongly suggest you to always upgrade your TFS to the latest version, to have all the latest bugfix and to avoid Big Bang upgrade that spans multiple versione (ex 2008 to 2013, or 2010 to 2015).

Gian Maria.

Invalidate cache of TFS after a Server Move

If you move your TFS server in a new hardware be sure to follow the instructions in MSDN: Move or clone Team Foundation Server (hardware move).

There are many reason why you want to move TFS to a different hardware, probably you want to use a new powerful hardware and you have not virtualized TFS, or you need to upgrade TFS and you need to move Sql to a new hardware with a more recent version of SQL. Sometimes you simply want to startup with a clean TFS machine (probably you installed too much stuff in the old one, or you have some other services running in the very same machine).

One of the important step is refreshing the data cache on client computers, sometimes if you forget to follow this step client start behaving weird. An example could be: a user is reporting that Visual Studio shows some files as “pending add” but the file was already in TFVC and also the user is able to see the file from the web interface of TFS. The problem is that Visual Studio erroneusly believe that a file needs to be added to source code repository but the file is already there.

To globally invalidate all caches for all users you can use the witadmin rebuildcache command (as described in previous listed MSDN article). With this command you are sure that, upon new connection, all clients will have cache invalidated.

Also follow this instruction to refresh the Version Control Cache on client computers to ensure that all workspaces are in sync with the new server.

Always remember, after moving TFS to a new hardware it is a good idea to invalidate cache from server and to tell all users to refresh local version control cache to avoid weird problems.

Gian Maria.

Troubleshoot Error TF14044 in build vNext for TFS2015

I upgraded a TFS2012 to TFS2015 Update 1 at a customer site and one of the reason why the customer want to upgrade is the new build system introduced in TFS 2015. Sadly enough, after the upgrade we created a simple build but it failed returning a permission error.

TF14044: Access Denied: User Project Collection Build Service (TEAM FOUNDATION) needs the CreateWorkspace global permission(s).

We were really puzzled, because the user used to run the build (TFSBuild) was correctly set into the Project Collection Build Service account, and that group has all the permissions to create a workspace. We double check permissions for TFSBuild and Project Collection Build Service account and everything is ok, still the error was there.

Error of the build

Figure 1: Error raised for any build created with the new build system

After spending some time double checking all permissions for the various groups without any success I realized that I did not read with attention error message TFS was giving to me. The error is telling me: User Project Collection Build Service needs the CreateWorkspace and the key is on the word User.

To solve this problem simply open the security page of the Project Collection and select the Users tab. In this screen you should be able to see all the users that belongs to the collection and you should find a couple of special users called Project Build Service (TEAM FOUNDATION) and Project Collection Build Service (TEAM FOUNDATION).

The two users related to the new Build System

Figure 2: The two users related to new Build System

It turned out that those two users really did not have correct permission to create a workspace (due to some security restriction) and they does not belong to the Project Collection Build Service TFS Group. To solve this problem simply add those two users (Project Build Service (TEAM FOUNDATION) and Project Collection Build Service (TEAM FOUNDATION)) to the Project Collection Build Service Group, so they will have all needed permission to issue a build.

If you are curious why are there two special Users to run the build, the reason is the ability on the new build system to choose the level of authorization you need on the general tab.

Build Job authorization scope for new build system.

Figure 3: Build Job authorization scope for new build system.

Choosing Project Collection scope is needed if the build needs to access data from multiple Team Projects, if the build operates in a single Team Project you can safely use the Current Project setting.

Gian Maria