How can I use PowerShell to update assembly properties on previous TFS assemblies?

We use TFSDeployer to listen for build quality and deployment changes in our staging environment as we move to the "stage".

I would like this to continue and update all other assemblies that currently have the "Staging" build quality rejected.

This is similar to what should happen inside the PowerShell script, which looks like this:

$droplocation = $TfsDeployerBuildData.DropLocation
ECHO $droplocation

$websourcepath = $droplocation + "\Release\_PublishedWebsites\CS.Public.WebApplication\"
$webdestinationpath = "\\vmwebstg\WebRoot\CreditSolutions\"

new-item -force -path $webdestinationpath -itemtype "directory"
get-childitem $webdestinationpath | remove-item -force -recurse
get-childitem $websourcepath | copy-item -force -recurse -destination $webdestinationpath

$configFile = $webdestinationpath + "web.development.config"
remove-item $configFile -force

$configFile = $webdestinationpath + "web.staging.config"
$configFileDest = $webdestinationpath + "web.config"
move-item $configFile $configFileDest -force

So how can I do this?

+3
source share
2 answers

First add the Get-tfs function to your script:

function get-tfs (
    [string] $serverName = $(Throw 'serverName is required')
)
{
    # load the required dll
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")

    $propertiesToAdd = (
        ('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'),
        ('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'),
        ('BS', 'Microsoft.TeamFoundation.Build.Common', 'Microsoft.TeamFoundation.Build.Proxy.BuildStore'),
        ('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'),
        ('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService')
    )

    # fetch the TFS instance, but add some useful properties to make life easier
    # Make sure to "promote" it to a psobject now to make later modification easier
    [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
    foreach ($entry in $propertiesToAdd) {
        $scriptBlock = '
            [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null
            $this.GetService([{1}])
        ' -f $entry[1],$entry[2]
        $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock)
    }
    return $tfs
}

Then create an instance of the TFS object

$tfs = get-tfs http://YourTfsServer:8080

Then find builds with build quality "Staging"

$builds = $tfs.BS.GetListOfBuilds("Test Project", "TestBuild") | 
where {$_.BuildQuality -eq "Staging"}

,

 foreach ($build in $builds) { $tfs.BS.UpdateBuildQuality($build.BuildUri, "Rejected") }

( script, )

: Team Foundation PowerShell

, script, TfsDeployer, 2 script , Staging → !

+3

, TFSDeployer PowerScript. .NET API Team Build . IBuildDetail . , BuildUri ( , ), IBuildServer.GetBuild .

IBuildServer QueryBuilds, , , Quality IBuildDetails, , Save() .

, - , .

+1

Source: https://habr.com/ru/post/1703691/


All Articles