locked
how to modify the TFS build definition ProcessParameters programmatically? RRS feed

  • Question

  • Hi All,

    Here i need some suggestion :

    how to modify the TFS build definition ProcessParameters programmatically?

    Best Regards

    Monday, July 23, 2012 8:47 AM

Answers

  • Hi Cathy Kong,

    Thanks for the reply and thanks for other responders as well.

    I found a way to , but a crude way of doing.

    1. Gets an XML formatted string representing all the process parameters for this build
    2. write the XML formatted string to a XML file.

    3. edit the xml  file to modify the process parameters.(just like any other xml editing)

    4. Now load the modified xml file into a xml formatted string
    5. and set it back to the buildDefinition.

    Regards

    Mougeelita

    Tuesday, July 24, 2012 8:33 AM

All replies

  • Hello,

    If you are looking to modify build definitions, you would have to open the build process template (the xaml file). In there, you can add parameters or modify values of existing parameters.

    Thank you,
    Alin,
    PRAKTIK Group
    TFS Hosting and TFS Consulting Services.
    Monday, July 23, 2012 2:00 PM
  • Hi Alin,

    Can you give some pointers to  modify values of existing parameters.

    Regards

    Tuesday, July 24, 2012 3:49 AM
  • Hi,

    Here is a good place to start.

    Thank you,
    Alin,
    PRAKTIK Group
    TFS Hosting and TFS Consulting Services.
    Tuesday, July 24, 2012 4:07 AM
  • Hi mougeelita,

    Thanks for your post!

    In addition to Alin, Can you look at the following code?

    // Connect to TFS and build server
    TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("http://myserver.com:8080/tfs/defaultcollection"));
    IBuildServer buildServer = tfs.GetService<IBuildServer>();
    var teamProject = "CI_Testing";
    var buildDetails = buildServer.QueryBuildDefinitions(teamProject);
    // DEV A
    foreach (var build in buildDetails)
    {
       
    var buildDefinition = buildServer.CreateBuildDefinition(teamProject);
        buildDefinition
    .BuildController = build.BuildController;
        buildDefinition
    .Name = "DEV_A_" + build.Name;
       
    // Get template
       
    var template = buildServer.QueryProcessTemplates(teamProject).Where(p => p.TemplateType == ProcessTemplateType.Custom).ElementAt(1);
        buildDefinition
    .Process = template;
       
    // Set process parameters
       
    var process = WorkflowHelpers.DeserializeProcessParameters(buildDefinition.ProcessParameters);
       
    // Custom build definition metadata parameters go here
        process
    ["BetaReleaseFolderForWebsiteAndDbScript"] = "** Custom argument goes here **";
        process
    ["DeploymentFolderForDbScript"] = "** Custom argument goes here **";
        process
    ["MaxNetDbProjectTargetDatabaseName"] = "** Custom argument goes here **";
        process
    ["ReleaseFolderForWebsiteAndDbScript"] = "** Custom argument goes here **";
        process
    ["TargetDataSourceName"] = "** Custom argument goes here **";
        process
    ["WorkspaceMainFolderName"] = "** Custom argument goes here **";
       
    // Set BuildSettings properties
       
    BuildSettings settings = new BuildSettings();
        settings
    .ProjectsToBuild = new StringList("$/CI_Testing/DEV_A_MAIN_branch/Module 1/module_1_code/module_1_code.sln");
        process
    .Add("BuildSettings", settings);
        buildDefinition
    .ProcessParameters = WorkflowHelpers.SerializeProcessParameters(process);
        buildDefinition
    .Save();
    }

    Quote from http://social.msdn.microsoft.com/Forums/nl-BE/tfsbuild/thread/ff3873f5-44b7-4607-8f3e-ae16aa388a6e

    Hope it helps!

    Best Regards,


    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 24, 2012 8:04 AM
    Moderator
  • Hi Cathy Kong,

    Thanks for the reply and thanks for other responders as well.

    I found a way to , but a crude way of doing.

    1. Gets an XML formatted string representing all the process parameters for this build
    2. write the XML formatted string to a XML file.

    3. edit the xml  file to modify the process parameters.(just like any other xml editing)

    4. Now load the modified xml file into a xml formatted string
    5. and set it back to the buildDefinition.

    Regards

    Mougeelita

    Tuesday, July 24, 2012 8:33 AM
  • Hi Mougeelita,

    Thanks for sharing the experiences here, and I am sorry not to help you.

    Best Regards,


    Cathy Kong [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, July 25, 2012 1:51 AM
    Moderator