The Teamprise TFS Ant Tasks are created and supported by Teamprise. For more information, go to the index page or visit teamprise.com.
These tasks provide an interface to Microsoft Team Foundation Server. By using these tasks you can access the capabilities of a TFS server from an Ant script. The TFS Ant tasks require Ant version 1.6 or higher. Version 1.7.0 is recommended.
These tasks are implemented as wrappers around the tf command line tool for accessing TFS.
These tasks will work with either the tf.exe
tool from Microsoft or the Teamprise command line client.
Usage of these tasks requires that the command line tool is already installed on the machine running Ant.
Important: These tasks need "tf" to be on the path. Alternatively, you can set the property
tfs.vc.executable to the location of the tf program to execute.
If the tasks aren't working, check that one of these conditions is met.
| Task | Description |
| tfs | Run a generic tfs command |
| tfsadd | Add files or folders to a workspace |
| tfscheckin | Check in pending changes |
| tfscheckout | Check out files and folders so they can be edited |
| tfsdelete | Delete files or folders from a workspace |
| tfsget | Get files and folders from the server |
| tfshistory | Obtain history information on a file or folder |
| tfslabel | Manage labels |
| tfsparsehistory | Parses the output from tfshistory |
| tfstasksdiagnostics | Prints out diagnostic information and tests that the Teamprise TFS Ant tasks are correctly installed |
| tfsworkfold | Manage working folder mappings for a workspace |
| tfsworkspace | Manage workspaces on a TFS server |
Each of the tasks below requires information specifying the TFS server to connect to and the credentials to use when logging in. These values can be individually specified for each task as attributes or globally specified as properties. Note: the per-task attributes take precedence over the global properties. If both a global property and the corresponding per-task attribute is set, the value of the per-task attribute will be used.
| Property | Attribute | Description | Examples |
| tfs.server | server | The URL of the TFS server to connect to | http://tfs.mycompany.com:8080 |
| tfs.user | user | The username (optionally qualified by domain) to use when connecting to the server | myusername MYDOMAIN\myusername |
| tfs.password | password | The password to use when connecting to the server | mypassword |
Important: When specifying a username using the DOMAIN\USERNAME syntax, be sure to use only a single backslash. Escaping the backslash is not neccessary inside an Ant script.
In certain cases, these connection details are optional and do not need to be specified. However, it's usually best to always specify them explicitly rather than rely on the inferring behavior of the command-line tool that works under some conditions but not others.
Additionally, the TFS tasks support the following configuration options. Again, these can be set either as global properties or as per-task attributes.
| Property | Attribute | Description | Required |
| tfs.failonerror | failonerror | Specifies whether to stop the build
(true)
or keep going (false)
if an error is returned from the tf command. |
No; defaults to true. |
| tfs.failifexecutionfails | failifexecutionfails | Specifies whether to stop the build if the task is
unable to launch the TFS command-line tool. If false,
a launch error will generate a line in the Ant log and the build will
continue. |
No; defaults to true. |
| tfs.verbose | verbose | Specifies the verbosity of the TFS task. For now, the only possible values
are true and false. When verbose is true, the task will display
the tf command line that it will execute before executing it. In the future, different
levels of verbosity will be supported, including the ability to supress tf output if desired. |
No; defaults to true. |
| tfs.timeout | timeout | Stop the wrapped command-line tool if it doesn't finish within the specified time (given in milliseconds). | No |
| tfs.dir | dir | Specifies the working directory in which the command-line tool wrapped by the task will be executed. | No; defaults to the project's basedir. |
| tfs.vc.executable | executable | Specifies the location of the TFS command-line
tool to execute. For example, you could set this value to
C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\tf.exe,
or /~/teamprise/clc/tf. |
No; defaults to "tf". |
| N/A | newenvironment | If true, the task will not propagate the old environment to
the wrapped command-line tool when new environment variables are specified using nested
<env> elements. If no new environment variables are specified,
the old environment will always be propagated regardless of the value of the newenvironment
attribute.
|
No; defaults to false. |
Each of the TFS tasks supports a number of optional per-task attributes that allow you to redirect the input and output of the underlying command-line tool. For example, you can use these properties to capture the output of a TFS task and write it to a file or Ant property instead of writing it to the Ant log.
| Attribute | Description |
| output | Name of a file to which to write the output of the wrapped command-line tool. If the error stream is not also redirected to a file or property, it will appear in this output. |
| error | The file to which the standard error of the wrapped command-line tool should be redirected. |
| outputproperty | The name of a property in which the output of the wrapped command-line tool should be stored. Unless the error stream is redirected to a separate file or stream, this property will include the error output. |
| errorproperty | The name of a property in which the standard error of the wrapped command-line tool should be stored. |
| resultproperty | The name of a property in which the exit code of the wrapped command-line tool should be stored. |
| successproperty | The name of a property which will be set to the string
true if the wrapped command-line tool execution succeeds (based
on the exit code of the tool). |
| failureproperty | The name of a property which will be set to the string
true if the wrapped command-line tool execution fails (based
on the exit code of the tool). |
| logerror | This attribute is used when you wish to see error output in Ant's log and you are redirecting output to a file/property. The error output will not be included in the output file/property. If you redirect error with the "error" or "errorProperty" attributes, this will have no effect. |
| append | Whether output and error files should be appended to or overwritten. Defaults to false (overwrite). |
| input | A file from which the wrapped command-line tool's standard input is taken. This attribute is mutually exclusive with the inputstring attribute. |
| inputstring | A string which serves as the input stream for the wrapped command-line tool. This attribute is mutually exclusive with the input attribute. |
Using global properties to specify TFS connection details:-
<property name="tfs.server" value="http://tfs.mycompany.com:8080"/> <property name="tfs.user" value="MYDOMAIN\autobuild"/> <property name="tfs.password" value="access"/>
Using task attributes to specify TFS connection details:-
<tfsWhatever server="http://tfs.mycompany.com:8080" user="MYDOMAIN\autobuild" password="access" . . . />
Using global properties to specify the location of the command-line executable:
<property name="tfs.vc.executable" value="c:\program files\microsoft visual studio 8\common7\ide\tf.exe" />
Capturing the output of a TFS task in a property instead of having the output go to the Ant log:
<tfsWhatever outputproperty="myprop" />
<echo message="${myprop}" />
All of the TFS tasks can pass custom arguments and options to the wrapped
command-line tool by using nested elements. The main use of this feature is as
a stop-gap measure to provide functionality not available through the built-in
attributes of a task, or to allow workarounds for bugs in the Ant/TFS integration.
The generic tfs task will usually need to use these
nested elements in order to be useful.
Custom command line arguments should be specified as nested
<arg> elements. See Command line arguments.
When possible, nested <option> elements should be used instead,
as the wrapped command-line tool's switch syntax does not have to be manually
specified.
Custom command line options should be specified as nested
<option> elements. Used nested option elements is preferred to
using nested argument elements (when the value is really an option and not a free-form
argument) because the Ant script does not need to hard-code the switch syntax. The
switch syntax is the leading prefix character ('/' or '-') and the separator
character between the option name and option value (':'). The switch syntax
may be platform-specific.
| Attribute | Description | Required |
| name | The name of the option. | Yes |
| value | The value of the option, if any. | No |
It is possible to specify environment variables to pass to the
command-line tool via nested <env> elements.
| Attribute | Description | Required |
| key | The name of the environment variable. | Yes |
| value | The literal value for the environment variable. | Exactly one of these. |
| path | The value for a PATH like environment variable. You can use ; or : as path separators and Ant will convert it to the platform's local conventions. | |
| file | The value for the environment variable. Will be replaced by the absolute filename of the file by Ant. |
A nested I/O Redirector can be specified.
<tfsWhatever x="y"> <arg value="some value" /> <option name="myoption" value="myvalue" /> <env key="MY_ENV_VAR" value="myvalue" /> </tfsWhatever>
Several of the task descriptions below reference the versionspec format. A versionspec is a string that describes a particular version of a TFS item. The following table lists the five possible versionspec types and gives examples of each.
| versionspec type | Description | Example |
| Date / Time | Specifies a version of an item based on a point in time | D10/20/2005 |
| Changeset | Specifies a version of an item in a TFS changeset | C1256 |
| Label | Specifies a version of an item that has a given label | Lmylabel |
| Latest | Specifies the latest version of an item | T |
| Workspace | Specifies a version of an item in a given workspace | Wworkspacename;owner |
For more information about the versionspec format, see the online documentation.
Normally, when the execution of the wrapped command-line tool fails, the Ant build will fail as well. There are a few kinds of failures that can happen, and a few ways that you can configure a TFS task's behavior when the command-line tool fails.
The tf tool defines several standard
exit codes.
The exit code of the sub-prcess is used by the TFS task to determine what kind of failure
has happened. An exit code of 1 or 100 is the most common error
exit code. When this exit code is returned, the build will fail unless the
failonerror attribute is set to true (or the global
tfs.failonerror property is set to true). Any other non-zero
exit code indicates a bug in the TFS task itself and will always fail the build.
It is also possible that an error will occur when attempting to execute the command-line
tool, and the tool cannot be executed. An example of this kind of error would be that the
command-line tool executable could not be found. This kind of error will fail the build
unless the failifexecutionfails attribute is set to true (or
the global tfs.failifexecutionfails property is set to true).
Runs a generic TFS command. This task is intended as a stop-gap measure when some functionality is needed that one of the other TFS tasks does not provide. This task gives full control over the options and arguments that are passed to the TFS command line client. For a complete listing of the available commands and their syntax, consult the online documentation.
| Attribute | Description | Required |
| command | The name of the TFS command to execute. This name will become the first argument
after the name of the command-line executable. workspaces and get are examples
of valid version control commands. |
Yes |
Tip: When the global tfs server property is set (tfs.server),
the server option will be automatically included when invoking the command line client.
Certain TFS commands will error or show a warning if the server option is passed.
Occasionally when using the <tfs> task when the global server property
is set, you may wish to suppress this option for certain TFS commands to avoid errors or
warnings. By using the per-task server attribute and setting the value to an empty string,
you can suppress the server option. The per-task attributes always override the global
properties. See above for more information on TFS task configuration.
The examples section shows an example of supressing the global server property when using this
task.
List workspaces and store the results in a property:
<tfs command="workspaces" outputproperty="myprop" />
<echo message="${myprop}" />
Run the status command to see pending changes against an item:
<tfs command="status" server="">
<arg file="${basedir}/files/project" />
</tfs>
Run the properties command to display properties for a folder and all contained items:
<tfs command="properties"> <option name="recursive" /> <arg value="$/myproject/myfolder" /> </tfs>
Pends adds for new items to a workspace. To commit the new items, you must perform a check-in
(tfscheckin).
This task wraps the
tf add command.
| Attribute | Description | Required |
| recursive | true to perform a recursive add of the specified local item. |
No; defaults to true. |
| lock | Specifies the lock level to use when adding new items. Must be one of
none, checkin, or checkout.
See tfscheckout for more information. |
No; defaults to none. |
| item | The local item to perform the check-in on. | Yes |
Add an item to TFS version control:
<tfsadd
item="${basedir}/files/newfolder" />
Add an item to TFS version control, specifying a lock:
<tfsadd
lock="checkin"
item="${basedir}/files/newfolder" />
Checks in items that have been previously checked out in a workspace.
This task wraps the
tf checkin command.
| Attribute | Description | Required |
| recursive | true to perform a recursive check-in on the specified local item. |
No; defaults to true. |
| comment | The comment to give the check-in. | No |
| notes | The check-in note(s) to give the check-in. See below. | No |
| item | The local item to perform the checkin on. | Yes |
Check-in notes are specified in the following format:
NoteFieldName=NoteFieldValue
You can provide multiple, semicolon-separated "field=value" expressions.
Check an item in:
<tfscheckin
comment="checked in by build process"
item="${basedir}/files/build/version.txt" />
Check an item in, specifying some check-in notes:
<tfscheckin
comment="checked in by build process"
notes="Code Reviewer:${codereviewer};Security Reviewer:${securityreviewer}"
item="${basedir}/files/build/version.txt" />
Check items out. Before checking an item out, you must ensure that the item is mapped in a workspace
(tfsworkfold) and that the item exists locally
(tfsget). By checking an item out, the local file or folder is made writable. Changes to that
item can later be checked in (tfscheckin).
This task wraps the
tf checkout command.
| Attribute | Description | Required |
| recursive | true to perform a recursive check-out on the specified local item. |
No; defaults to true. |
| lock | Specifies the lock level to use when checking items out. Must be one of
none, checkin, or checkout. See the table below. |
No; defaults to none. |
| item | The local item to perform the check-out on. | Yes |
| Value | Description |
| none | No lock is applied to the checked-out items. |
| checkin | Other users can also check out the items, but they can not check them in until you release the lock by checking them in first. |
| checkout | Other users can not check out the same items until you release the lock by checking them in. |
For more information on the lock attribute, see Understanding Lock Types in the MSDN documentation.
Check an item out:
<tfscheckout item="${basedir}/files/build/version.txt" />
Check an item out, locking it so that other users cannot check it in until you do:
<tfscheckout
lock="checkin"
item="${basedir}/files/mydirectory" />
Pends deletes for items in a workspace. To commit the deletions, you must perform a check-in
(tfscheckin).
This task wraps the
tf delete command.
| Attribute | Description | Required |
| recursive | true to perform a recursive delete of the specified local item. |
No; defaults to true. |
| lock | Specifies the lock level to use when deleting items. Must be one of
none, checkin, or checkout.
See tfscheckout for more information. |
No; defaults to none. |
| item | The local item to perform the delete on. | Yes |
Delete an item from TFS version control:
<tfsdelete
item="${basedir}/files/newfolder" />
Performs a get on a local path that has previously been mapped in the specified workspace.
This task wraps the
tf get command.
| Attribute | Description | Required |
| recursive | true to perform a recursive get on the specified local path. |
No; defaults to true. |
| all | true to perform the get with the "all" option enabled. All items will be
re-downloaded from the server, even items the server already considers to be local. |
No; defaults to false. |
| overwrite | true to perform the get with the "overwrite" option enabled. Any local files
that are writable and not checked out will be overwritten. |
No; defaults to false. |
| force | true to use "force" mode, which implies both all and overwrite options.
When the force attribute is set, the all and overwrite attributes will be ignored. |
No; defaults to false. |
| localpath | The absolute path of a local item to perform a get for. A server path can not be specified instead of a local path. | Yes |
| version | A versionspec used to identify the version of the item to get. | No; defaults to the latest version. |
Perform a simple recursive get on a path:
<tfsget localpath="${basedir}/files" />
Peform a get of items at a specific changeset version:
<tfsget localpath="${basedir}/files" version="C128" />
Perform a get, re-downloading any items already downloaded and overwriting local writable files:
<tfsget localpath="${basedir}/files" force="true" />
Obtains the history of an item on the TFS server.
This task is often used inconjunction with the outputproperty attribute that
all TFS tasks support (see above). Using outputproperty allows the history output
to be saved in an Ant property and used later in the build. By calling the
tfsparsehistory task with the output of this task, individual
values can be pulled out of the history output (like changeset numbers and dates).
This task wraps the
tf history command.
| Attribute | Description | Required |
| stopafter | Specifies a number of changesets to display history for. | No |
| format | The format of the history data to set into the property.
One of brief, or detailed. The brief format
displays a single line for each changeset in the history, while detailed
shows multiple lines and extended information for each changeset. Currently, only
the brief format is supported for use with the
tfsparsehistory task. |
No; defaults to brief. |
| recursive | true to obtain recursive history for child items. |
No; defaults to true. |
| item | The itemspec to obtain history for. | Yes |
| version | The versionspec used to identify which item to obtain history for. | No |
Get the history for an item and store it in a property:
<tfshistory
outputproperty="myprop"
logerror="true"
format="briefquot;
item="$/MyProject/myfolder" />
<echo message="${myprop}" />
Display detailed history for only the last changeset of an item:
<tfshistory format="detailedquot; stopafter="1" item="$/MyProject/myfolder" />
Attaches or removes labels from a version of an item on the TFS server. Adds or removes of labels happen immediately:
no subsequent check-in is required.
This task wraps the
tf label command.
| Attribute | Description | Required |
| name | The name of the label being attached or removed. | Yes |
| mode | One of add (attach a label) or
delete (remove a label). |
No; defaults to add. |
| recursive | true to perform a recursive label operation. |
No; defaults to true. |
| item | The itemspec to perform the label on. | Yes |
| version | The versionspec used to identify the version of the item to perform the label on. | No |
Create a label on an item:
<tfslabel
name="${buildLabel}"
item="${basedir}/files" />
Parses the output of the tfshistory task. Unlike most of the other TFS tasks, this task does not invoke any underlying command-line tool. The purpose of this task is to take TFS history data (usually stored in a property from a previous call to tfshistory) and pull out an individual value.
Important: currently, this task only works with history data in the "brief" format. Attempting to use this task with history in the "detailed" format will not work.
The history data is in tabular form. The purpose of this task is to parse the table and pull out the value of a single cell. You must specify the index of the row to pull data from, as well as either the column name or column index. Note that the indices are one-based, so the first row index is "1" and the first column index is "1"
| Attribute | Description | Required |
| historyinputvalue | The history value to parse. Important: This attribute must be set to the value itself, not the name of a property that holds the value. | Yes |
| historyoutputproperty | The name of a property in which the extracted cell value will be stored. | Yes |
| rowindex | The one-based index into the table's rows from which to pull out data. Any header rows do not count - row index "1" is the first row of changeset data. | Yes |
| columnindex | The one-based index into the table's columns from which to pull out data. | Either columnindex or columnname must
be specified.If both are specified, columnname will be ignored. |
| columnname | The name of the column from which to pull out data. When comparing the table's columns to the value of this attribute, case is ignored. |
The most common use of this task is to pull out changeset information for an item. This example shows how to obtain the latest changeset number of an item:
<tfshistory
outputproperty="historydata"
stopafter="1"
item="$/MyProject/myfolder" />
<tfsparsehistory
historyinputvalue="${historydata}"
historyoutputproperty="changeset"
rowindex="1"
columnname="changeset" />
<echo message="changeset is: ${changeset}" />
Prints out diagnostic information and runs tests to ensure that the Teamprise TFS Ant tasks are correctly installed. This task takes no parameters.
<target name="diagnostics">
<tfstasksdiagnostics />
</target>
Creates and deletes working folder mappings in a workspace.
This task wraps the
tf workfold command.
| Attribute | Description | Required |
| workspace | The workspace name to create the mapping in or remove the mapping from. | Yes |
| mode | The mode of the tfsworkfold task. One of
map, unmap, or list. |
See below |
| localpath | The absolute local path to map to the specified server path. | See below |
| serverpath | The absolute server path to map to the specified local path. | See below |
The map and unmap modes are used to create and remove working folder
mappings from a workspace. The list mode is used to display all existing working folder
mappings in a workspace, and is intended primarily for debugging Ant scripts.
When at least one of serverpath or localpath is specified, mode defaults
to map if it is not specified. When neither of serverpath and localpath is specified, mode
defaults to list if it is not specified.
When mode is map, both serverpath and localpath are required. When mode is unmap,
either serverpath or localpath is required, and if both are specified serverpath will be used. The list
mode does not require either serverpath or localpath to be specified.
Create a new working folder mapping:
<tfsworkfold
workspace="autobuild_workspace"
mode="map"
localpath="${basedir}/files"
serverpath="$/MyProject/myfolder" />
List the working folder mappings in a workspace:
<tfsworkfold workspace="autobuild_workspace" />
Remove a working folder mapping:
<tfsworkfold
workspace="autobuild_workspace"
mode="unmap"
localpath="${basedir}/files"
Creates or deletes a workspace on the TFS server.
This task wraps the
tf workspace command.
| Attribute | Description | Required |
| mode | The mode of the tfsworkspace task. One of
create, delete, new, or
remove. create and new are
aliases, as are delete and remove. |
No; defaults to create |
| workspace | The workspace name. | Yes |
Create a new workspace:
<tfsworkspace mode="create" workspace="autobuild_workspace" />
Delete a workspace:
<tfsworkspace mode="delete" workspace="autobuild_workspace" />
Delete a workspace if it exists, but do not fail the build if the workspace does not exist:
<tfsworkspace mode="delete" workspace="autobuild_workspace" failonerror="false" />
| January 2007 | V1.0 | Initial release |
| July 2007 | V1.1 | Fixed error codes permissible for "failonerror=false", to be 1 or 100. See Command-Line Exit Codes for more details. |
| December 2007 | V1.2 |
|
Copyright © Teamprise, 2007-2008. All rights reserved.