Geeks With Blogs

News




View Tarun Arora's profile on LinkedIn

profile for Tarun Arora at Stack Overflow, Q&A for professional and enthusiast programmers

Tarun Arora - Visual Studio ALM MVP ALM, Agile, Automation, Performance Testing, Software QA, Cloud, ...

Introduction

It is common for your code projects to reference Microsoft or Non Microsoft SDKs, this requires that the build agents has the SDK’s 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 SDK's 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.

         DisplayName = Convert deployment script filename
         Input = DeploymentScript
         Result = DeploymentScriptFilename
         Workspace = Workspace

  • Click on the InvokeProcess activity and change the properties

          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 here 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!

Posted on Sunday, February 3, 2013 11:10 PM TFS2010 , TfsService , TFS2012 , ALM | Back to top


Comments on this post: TFS - Get List Of Software Installed On Build Agent

# re: TFS - Get List Of Software Installed On Build Agent
Requesting Gravatar...
Wow great post Tarun! There's just a ton of detail here. I've always been scared to dig into the TFS process templates and mess with the sequences because it seems so overwhelming. This post might just sway me!
Left by Ben Barreth on Feb 04, 2013 2:09 PM

# re: TFS - Get List Of Software Installed On Build Agent
Requesting Gravatar...
Ben / Tarun,
Turning on the Document Outline window in VS2012 makes working with the Build Process Templates much less overwhelming. :)

Aaron
Left by Aaron Kowall on Feb 04, 2013 7:58 PM

comments powered by Disqus

Copyright © Tarun Arora [Microsoft MVP] | Powered by: GeeksWithBlogs.net | Join free