by Ewald Hofman
27. April 2010 04:47
In the series the following parts have been published
- 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
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.
- First open Visual Studio 2010 and go in Source Control to the folder BuildProcessTemplates of the team project you want to modify
- Double click the DefaultTemplate.xaml file to open up the workflow. This might take a while.
- A similar window should pop up now
- In the bottom of the screen you see the Variables, Arguments and imports
- Click on the Arguements, which will open up the list of arguments that exist on the current build process template.
- Go to the end of the list, and click on the cell that shows Create Argument.
- Change the argument1 name into TestMessage and accept the rest of the values
- 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
- This will open the Process Parameter Metadata Editor.
- Click on the Add button and add the TestMessage argument you just added.
- Press OK to accept the changes.
- Now click on the Variables to open up the variables. You will see an empty list, because a variable is scoped to an activity.
- So click on the top activity called Sequence
- 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.
- Now add a new variable called “MyTestMessage” by clicking on the Create Variable cell.
- 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.
- Type in "Hello " + TestMessage
- Now open the toolbox, which might take a while, and search for the WriteBuildMessage activity in the “Team Foundation Build Activities” tab
- Now drag ‘n drop the WriteBuildMessage to the workflow, just under the Get the Build
- When you select the activity and open the properties window, you can set the properties of the activity.
- 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
- 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”
- Save the build definition and queue it. While the build executes, you will see our exciting message
You can download the full solution at BuildProcess.zip. It will include the sources of every part and will continue to evolve.