1

I tried to set a Build Process Parameter by a C# program which uses the TFS API. This BuildDefinition is a BuildDeployTest workflow (slightly modifie LabDefaultTemplate.11.xaml). I am able to change all the Lab Process Settings (Lab Workflow Parameters) by this code:

System.Collections.Generic.IDictionary<string, object> myDictionary = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
foreach (var Parameter in myDictionary)
{
    if (Parameter.Key == "LabWorkflowParameters")
    {
        // copy the entry
        Microsoft.TeamFoundation.Lab.Workflow.Activities.LabWorkflowDetails myCopy = Parameter.Value as Microsoft.TeamFoundation.Lab.Workflow.Activities.LabWorkflowDetails;
        foreach(TestAgentListItem testAgent in listOfTestAgents)
        {
            if(testAgent.Checked == true)
            {
                myCopy.EnvironmentDetails.LabEnvironmentName = testAgent.TestAgentName;
                myCopy.EnvironmentDetails.LabEnvironmentUri = new Uri(testAgent.LabEnvironmentUri);
                break;
            }

        }

        myDictionary[Parameter.Key] = myCopy;
    }
    break;
}

request.ProcessParameters = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.SerializeProcessParameters(myDictionary);

// trigger a new Build
buildServer.QueueBuild(request);

I have another Build process parameter called "TestDirectory" which is shown under Build process parameters -> 3. Misc -> TestDirectory. I tried to change this parameter by myDictionary["TestDirectory"] = @"TestDir"; but it doesn't change. In PowerShell I'm able to change this parameter by just typing

[Microsoft.TeamFoundation.Build.Client.IBuildDefinition] $BuildDef = $buildserver.GetBuildDefinition($project,$buildDefinition)
[Microsoft.TeamFoundation.Build.Client.IBuildRequest] $BuildReq = $BuildDef.CreateBuildRequest();
$processParameters = [Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers]::DeserializeProcessParameters($BuildReq.ProcessParameters)
$processParameters.TestDirectory = "TestDir"

but how can I do this with C#?

Regards

1 Answer 1

4

If you have assigned value already it will not change.

Try below:

string argumentName = "TestDirectory";
var process = Microsoft.TeamFoundation.Build.Workflow.WorkflowHelpers.DeserializeProcessParameters(BuildDefinition.ProcessParameters);

if (process.ContainsKey(argumentName))                             
{
    process.Remove(argumentName);
    process.Add(argumentName, attributeValue);
    BuildDefinition.ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
    BuildDefinition.Save();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.