Quantcast
Channel: Geekswithblogs.net | asp.net Posts
Viewing all articles
Browse latest Browse all 50

List of Software on TFS Service Hosted Build

$
0
0

A couple of weeks back I had posted a blog post on getting a list of software installed on the build agent by simply customizing the build process template. Building on top of the same solution, I have created a websitehttp://listofsoftwareontfshostedbuildserver.azurewebsites.net/” which gets updated once every day with the list of software installed on the TFS hosted build server.

In this blogpost, I’ll show you how I have implemented this solution, but first a screen shot of what information the website carries,

  • The name of the software installed on the TFS Service hosted build
  • The version of the install on the TFS Service hosted build
  • The Publisher of the software installed on the TFS Service hosted build
  • When that software was installed on the TFS Service hosted build
  • A link to help documentation

image

The Implementation

The implementation is fairly straight forward,

1. Configure the build process template to run power shell script http://geekswithblogs.net/TarunArora/archive/2013/02/03/tfs---get-list-of-software-installed-on-build-agent.aspx 

2. Create a SQL Azure database and add a table SoftwareDeployed, at the very basic level, the table should carry these columns,

     image

3. Change the powershell script to import sql ps snapins, store the results of the powershell query in the sql database

$ErrorActionPreference = "Stop"

$sqlpsreg="HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.SqlServer.Management.PowerShell.sqlps"if (Get-ChildItem $sqlpsreg -ErrorAction "SilentlyContinue")
{throw"SQL Server Provider for Windows PowerShell is not installed."
}else
{
    $item = Get-ItemProperty $sqlpsreg
    $sqlpsPath = [System.IO.Path]::GetDirectoryName($item.Path)
}


#
# Set mandatory variables for the SQL Server provider
#
Set-Variable -scope Global -name SqlServerMaximumChildItems -Value 0
Set-Variable -scope Global -name SqlServerConnectionTimeout -Value 30
Set-Variable -scope Global -name SqlServerIncludeSystemObjects -Value $false
Set-Variable -scope Global -name SqlServerMaximumTabCompletion -Value 1000

#
# Load the snapins, type data, format data
#
Push-Location
cd $sqlpsPath
Add-PSSnapin SqlServerCmdletSnapin100
Add-PSSnapin SqlServerProviderSnapin100
Update-TypeData -PrependPath SQLProvider.Types.ps1xml 
update-FormatData -prependpath SQLProvider.Format.ps1xml 
Pop-Location

$db_server = "ReplaceWithYourTargetDbName.database.windows.net"
$tblSoftwareDetail = "SoftwareDetail"
$username = "dbUserName"
$pwd = "dbPassword

# First, clear existing table
$sql_query_del = "Delete from $tblSoftwareDetail"
Invoke-Sqlcmd -ServerInstance $db_server -Database $db -Username $username -Password $pwd -Query $sql_query_del

# Get list of software installed on the build server
gp HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select DisplayName, DisplayVersion, Publisher, 
InstallDate, HelpLink, UninstallString | foreach {
    $name = $_.DisplayName
    $version = $_.DisplayVersion
    $publisher = $_.Publisher
    $installDate = $_.InstallDate
    $helplink = $_.HelpLink
    $uninstallLink = $_.UninstallString
    Write-Host " Display Name: $name, Version: $version, Publisher: $publisher, InstallDate: $installDate, 
Helplink: $helplink, UninstallLink: $uninstallLink"

    $sql_query = "INSERT INTO $tblSoftwareDetail (Name, Version, Publisher, InstallDate, Helplink, Uninstall) 
VALUES ('$name', '$version', '$publisher', '$installDate', '$helplink', '$uninstallLink')"
    Invoke-Sqlcmd -ServerInstance $db_server -Database $db -Username $username -Password $pwd -Query $sql_query
}

4. Configure the build to run on a daily schedule to ensure that the software repository list stays up to date.

     image

5. Create a windows azure website and publish a simple website to surface this information to the UI.

http://listofsoftwareontfshostedbuildserver.azurewebsites.net/

image

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!

 


Viewing all articles
Browse latest Browse all 50

Trending Articles