Reputation: 825
I am trying to update a build definition from a PowerShell script, but am running into an issue when trying to deserialize the process parameters.
My script
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Client.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Common.dll'
add-type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Workflow.dll'
$tfsCollectionUrl = "http://{myurl}/tfs/{mycollection}"
$server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
$buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDef = $buildServer.GetBuildDefinition("{MyProjectName}", "{MyBuildName}")
$processParams = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($buildDef.ProcessParameters)
$processParams
And the error
Exception calling "DeserializeProcessParameters" with "1" argument(s): "Set property 'Microsoft.TeamFoundation.Build.Common.BuildParameter.Json' threw an exception."
At line:14 char:1
+ $processParams = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHel ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : XamlObjectWriterException
Everything I have seen on how to do what I want to do (which is to update the build number format) gives me this exact code, so not sure where to go from here. The build definition and process parameters do come back, just not in a fashion that I can really work with.
We are on TFS 2013 Update 4, and the cmdlets are from the 2013 TFS PowerTools.
Upvotes: 0
Views: 459
Reputation: 825
I was missing a reference to Newtonsoft.Json.dll:
Add-Type -Path "C:\Folder\SharedAssemblies\Newtonsoft.Json.dll"
I added that in, and all was well.
Final script:
Add-Type -Path "C:\{Folder}\SharedAssemblies\Newtonsoft.Json.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Build.Workflow.dll"
$tfsCollectionUrl = "http://{myurl}/tfs/{mycollection}"
$server = new-object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection(New-Object Uri($tfsCollectionUrl))
$buildServer = $server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$buildDefinition = $buildServer.GetBuildDefinition("{MyProjectName}", "{MyBuildName}")
$processParams = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($buildDefinition.ProcessParameters)
$processParams.BuildNumberFormat = "`$(BuildDefinitionName)_`$(Year:yy).222.0`$(Rev:.r)"
$buildDefinition.ProcessParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::SerializeProcessParameters($processParams)
$buildDefinition.Save()
Upvotes: 1