Customize Team Build 2010 – Part 2: Add arguments and variables

by Ewald Hofman 27. April 2010 04:47

In the series the following parts have been published

  1. Part 1: Introduction
  2. Part 2: Add arguments and variables
  3. Part 3: Use more complex arguments
  4. Part 4: Create your own activity
  5. Part 5: Increase AssemblyVersion
  6. Part 6: Use custom type for an argument
  7. Part 7: How is the custom assembly found
  8. Part 8: Send information to the build log
  9. Part 9: Impersonate activities (run under other credentials)
  10. Part 10: Include Version Number in the Build Number
  11. Part 11: Speed up opening my build process template
  12. Part 12: How to debug my custom activities
  13. Part 13: Get control over the Build Output
  14. Part 14: Execute a PowerShell script
  15. Part 15: Fail a build based on the exit code of a console application
  16. Part 16: Specify the relative reference path

 

In this post I am going to show you how you can add new arguments and variables in the build template. First, the difference between a variable and an argument is the following, according to http://msdn.microsoft.com/en-us/library/dd489456.aspx.

Variables are storage locations for data. Variables are declared as part of the definition of a workflow. Variables take on values at runtime and these values are stored as part of the state of a workflow instance. A variable definition specifies the type of the variable and optionally, the name.

Activity authors use arguments to define the way data flows into and out of an activity

In this post I will add a WriteBuildMessage activity to the default build process template that will show the message “Hello ?” where the ? will be the value of an argument, and the message will be stored in a variable.

  1. First open Visual Studio 2010 and go in Source Control to the folder BuildProcessTemplates of the team project you want to modify
  2. Double click the DefaultTemplate.xaml file to open up the workflow. This might take a while.
  3. A similar window should pop up now

    image
  4. In the bottom of the screen you see the Variables, Arguments and imports

    image
  5. Click on the Arguements, which will open up the list of arguments that exist on the current build process template.

    image
  6. Go to the end of the list, and click on the cell that shows Create Argument.

    image
  7. Change the argument1 name into TestMessage and accept the rest of the values

    image
  8. There is an interesting feature to add metadata to your arguments to tell Visual Studio how the user will see the argument when (s)he creates a new build definition. To do that, click on the button with ellipses (…) on the Metadata argument

    image
  9. This will open the Process Parameter Metadata Editor.

    image 
  10. Click on the Add button and add the TestMessage argument you just added.

    image 
  11. Press OK to accept the changes.
  12. Now click on the Variables to open up the variables. You will see an empty list, because a variable is scoped to an activity.

    image
  13. So click on the top activity called Sequence

    image  
  14. This will show the variable BuildDetail, which will be available during the complete lifetime of the build workflow and is set during the “Get the Build” activity.
  15. Now add a new variable called “MyTestMessage” by clicking on the Create Variable cell.

    image
  16. Now click on the Default cell for the MyTestMessage. When you start typing, you will see that it uses VB.Net as the language and that it supports intellisense.
  17. Type in "Hello " + TestMessage

    image
  18. Now open the toolbox, which might take a while, and search for the WriteBuildMessage activity in the “Team Foundation Build Activities” tab

    image
  19. Now drag ‘n drop the WriteBuildMessage to the workflow, just under the Get the Build

     image
  20. When you select the activity and open the properties window, you can set the properties of the activity.

    image  
  21. Now set the Message property to the value of the variable, so set it to MyTestMessage. Also change the DisplayName to “Say hello” and the importance to High

    image
  22. Now save the build process template and it is time to execute a build against the new template to see the results of your kicking ass template. First edit the build definition and click on the Process step. You will see that the new argument is now available to you. Set the value to anything you like. I use “world”

    image
  23. Save the build definition and queue it. While the build executes, you will see our exciting message

    image 

 


 

You can download the full solution at BuildProcess.zip. It will include the sources of every part and will continue to evolve.

Tags:

Team Build | VSTS 2010

Comments

7/1/2010 10:15:58 AM #

dave

This is my second visit to your site!  I really enjoy your article and I believe I'll become a frequent visitor to your site! I enjoy your in depth posts about build 2010 customization and I enjoy the fact you are so knowledgeable about build 2010 customization.  Thanks for your time Smile

dave Brazil |

11/1/2010 1:14:16 PM #

Nate

Thank you for the detailed step-throughs and screen caps--that's very helpful as I try to learn this new tool.

I'm having a problem adding arguments to my template.  There are no errors as I add them or when I run the build, everything appears to go in fine and looks just the way you describe it.  But when I go to edit a build configuration that uses my customized template, my arguments never show up in the list.  There's no "step 4" category, and I expanded all the other items in the tree just in case, but do not see my arguments.

I've tried checking my changes in and restarting vs2010, but still no luck.  Any tips on how I can troubleshoot this?

Nate Canada |

11/1/2010 8:48:00 PM #

Ewald Hofman

- Did you add it to the arguments and not to the variables?
- Did you checkin you template?
- Did you try to add the argument to the Metadata argments?

Ewald Hofman Netherlands |

11/4/2010 8:31:07 AM #

Nate

Looks like it may have been a case of editing the wrong file.  Somehow I ended up with a couple different copies of my xaml files.

Nate Canada |

11/4/2010 4:26:10 PM #

pingback

Pingback from sidneyforcier.com

Team Build 2010: Reference Hint Paths – Part 2 (No Assembly Required) « Sid Forcier's Dev Blog

sidneyforcier.com |

11/9/2010 5:32:26 AM #

trackback

Part 14: Execute a PowerShell script

Part 14: Execute a PowerShell script

Ewald Hofman |

11/10/2010 9:14:18 AM #

pingback

Pingback from blogs.like10.com

TechDays 2010 Presentations « Microsoft Team Foundation Server, SharePoint Server, .NET, and SQL Server

blogs.like10.com |

11/11/2010 8:07:05 PM #

Binu Abraham

Great post..
We have different release folders (release 1, release 2 etc)under a single team project. We were trying to have one build definition for all release folders. I was thinking of 'somehow' (calling a batch file with tf workload???) adding the workspace mapping based on the parameter passed in (ex:Release1, Release 2) during the queuing of the build. I was wondering if this is possible or is there any other alternate way to acheive this?
Thanks very much

Binu Abraham Australia |

11/25/2010 5:57:00 AM #

Ewald Hofman

I have not did a deep dive in this, but I think it will be somewhat harder to do, because the workspace is metadata on the build. If that information is modifyable through the buildDetail (or another variable), you should be able to do that.

Ewald Hofman Netherlands |

12/2/2010 9:50:21 PM #

Phil

Ewald,

I have been using the DefaultTemplate and appear to be having unexpected behaviour from variables.

I changed scope of the BuildDirectory variable from "Run On Agent" to be “Sequence”. I then tried to reference BuildDirectory after and outside of the “Run On Agent” scope.  I found that the BuildDirectory contained the expected BuildDirectory string while in the "Run On Agent" scope, but didn’t when was after the "Run On Agent" scope, in spite of the Variable clearly being available.  Is there something special going on between Varaibles and the "Run On Agent" Activity?

Phil Australia |

12/23/2010 7:27:08 AM #

Julien BARLET

Hi Ewald,

Very nice post, congratulation.

Thanks you for all.

Julien BARLET France |

1/19/2011 8:28:02 AM #

Elistan

Hello Ewald,

I've performed all steps but I've got "4. Exciting changes" in step 22 (just first 3 parameters). Could you tell me what might be a problem?

Thank you

Elistan Canada |

1/19/2011 3:44:57 PM #

Ewald Hofman

Did you add the information to the Metadata argument?

Ewald Hofman Netherlands |

2/2/2011 4:12:36 AM #

Lennart Jansson

Hi Ewald, thanks for sharing some really great information!

I have a tricky question that I haven't been able to find the answer for...
If you add your arguments to the Metadata, is it then possible to arrange the categories into a tree?
Let's say fx I would like to have a main category with arguments called VITBuilds and the arguments in that category needs to be divided into subcategories, something like this:

VITBuilds
  SubCategory1
    Arg1
    Arg2
  SubCategory2
    Arg3
    Arg4

I have a quite complex build workflow with several custom activities where each activity requires several arguments so it would be nice if it was possible to group them together like that...

Thanks
Lennart

Lennart Jansson Sweden |

2/4/2011 8:12:59 AM #

Ewald Hofman

You cannot create nested categories, but you can create your own custom datatypes which allows your to create a datatype for every sub category and then display a summary for that SubCategory.

Ewald Hofman Netherlands |

4/4/2011 9:59:17 AM #

trackback

Build a Reporting Services Solution with MSBuild 4.0

I recently was tasked with setting up a build for a large solution of Reporting Services reports. The

Dave Lloyd's 2 Cents |

5/31/2011 8:21:57 AM #

trackback

Ewald’s posts on TFS Build 2010

Ewald Hofman , an ALM MVP, has written a great series of blog posts on Team Build in Team Foundation Server 2010.  The 2010 release introduces Windows Workflow as the overall orchestrator of the build process.  Ewald walks you through quite a few topics related to this and the other new features.  Check it out! Part 1: Introduction Part 2: Add arguments and variables Part 3: Use more complex arguments Part 4: Create your own activity Part 5: Increase AssemblyVersion Part 6: Use custom type for an argument Part 7: How is the custom assembly found Part 8: Send information to the build log Part 9: Impersonate activities (run under other credentials) Part 10: Include Version Number in the Build Number Part 11: Speed up opening my build process template Part 12: How to debug my custom activities Part 13: Get control over the Build Output Part 14: Execute a PowerShell script Part 15: Fail a build based on the exit code of a console application Part 16: Specify the relative reference path Technorati Tags: tfs 2010 , team build , windows workflow

Buck Hodges |

10/27/2011 6:18:12 PM #

pingback

Pingback from justaprogrammer.net

Continuous Integration with TFS2010, MSDeploy & VSDBCMD « Just A Programmer

justaprogrammer.net |

9/11/2014 11:37:07 PM #

pingback

Pingback from crazeanswers.biz

Select count doesn't relapse rows that have a law of 0 in SQLite? - Addario

crazeanswers.biz |

Comments are closed

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen


ClusterMap

Widget Statistics not found.

There is an error in XML document (0, 0).X

Recent comments

Comment RSS