Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / DevOps / TFS

TFS - Get List Of Software Installed On Build Agent

0.00/5 (No votes)
7 Feb 2013CPOL4 min read 8.6K  
TFS - get list of software installed on Build agent

Originally posted on http://geekswithblogs.net/TarunArora/archive/2013/02/03/tfs---get-list-of-software-installed-on-build-agent.aspx

Introduction

It is common for your code projects to reference Microsoft or non Microsoft SDKs, this requires that the build agents has the SDKs installed. It is also natural that some of your projects may have a hard dependency on the version of the SDK. For example, some of your projects may only compile with Azure 1.6 SDK. The absence of the required SDK may cause your builds to fail. I tend to use the TFS Service cloud Build Service a lot, a list of software installed on the provisioned build agents will make it simple for me to analyze if I have the SDKs and their correct version installed on agents. This doesn’t really stop at TFS Service, even while building on premise a list of installed software on the build service is equally useful.

Objective

In this blog post, I’ll show you how to customize the TFS build process template to get a detailed list of software installed on the build server. This post is applicable to TFS Service, TFS 2012 and TFS 2010.

Note – If you have access to log on to the build agent, you can very well get this information by logging onto the build server and looking at the add remove programs window. For those of you who don’t have access to log on to the build server or would like a list of installed software without having to manually figure this out from the build server may find the steps below useful.

Preview

As you can see in the screen shot below, the build output includes the list of software installed on the hosted build agent.

image

Walkthrough

I have a PowerShell script that returns the list of installed software on a machine…

PS> gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* 
|Select DisplayName, DisplayVersion, Publisher, InstallDate, HelpLink, UninstallString |ogv

image

I’ll have to customize the build process template to add an InvokeProcess activity which will call into my PowerShell script and print the output in the build activity.

Let’s get started ...

  • Create a copy of the build process template.

    image

  • Add a new argument called “DeploymentScript”.

    image

  • Set the appropriate settings in the metadata.

    image

  • Scroll down beneath the TryCatch activity called “Try Compile, Test, and Associate Changesets and Work Items”. Add a new If activity and set the condition to "Not String.IsNullOrEmpty(DeploymentScript)" to ensure it will only run when the argument is passed.

    image

    image

  • Add in the Then branch of the If activity, a new Sequence activity and rename it to “Start deployment”.

    image

  • Click on the activity and add a new variable called DeploymentScriptFilename (scoped to the “Start deployment” Sequence).

    image

  • Add a ConvertWorkspaceItem activity on the “Start deployment” Sequence.

    image

  • Add a InvokeProcess activity beneath the ConvertWorkspaceItem activity in the “Start deployment” Sequence. This is the important step, this is where we will specify that the PowerShell process needs to be called to execute the PowerShell script.

    image

  • Click on the ConvertWorkspaceItem activity and change the properties. This will allow us to convert the server script path to the local path on the build workspace.
    C#
    DisplayName = Convert deployment script filename 
    Input = DeploymentScript 
    Result = DeploymentScriptFilename 
    Workspace = Workspace
  • Click on the InvokeProcess activity and change the properties
    C#
    Arguments = String.Format(" ""& '{0}' "" ", DeploymentScriptFilename) 
    DisplayName = Execute deployment script 
    FileName = "PowerShell"

    image

  • To see results from the PowerShell command drop a WriteBuildMessage activity on the "Handle Standard Output" and pass the stdOutput variable to the Message property.

    image

    image

  • Check in the customized build template. You can download a working copy from here.
  • Check in the PowerShell script to get the list of installed software into the version control under a folder of your choice. I have created a folder Script and checked it in as in the screen shot below,

    image

  • Create a new build definition using the Customized Build Template. Make sure you choose the CustomBuildProcessTemplate.xaml, set the logging verbosity to Detailed and in the Scripts section, set the server path of the PowerShell script.

    image

  • Save the build definition and fire off the build, once the build completes, look at the build Log.

    image

Voila! Job done… Please download a working version of the custom process template from here. Hopefully, from now on, you won’t have to request your environment management team for a list of software installed on the build server and should just be able to self service this with each build run on the server.

I hope you find this blog post… If you have any feedback, please feel free to leave a comment. Thank you for taking the time out and reading this blog post. If you enjoyed the post, remember to subscribe to http://feeds.feedburner.com/TarunArora. Stay tuned!

Image 18

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)