Ant task

Azure Pipelines | Azure DevOps Server 2019 | TFS 2018 | TFS 2017 | TFS 2015

Use this task in a build or release pipeline to build with Apache Ant.


The build agent must have the following capability:

  • Apache Ant

YAML snippet

# Ant
# Build with Apache Ant
- task: Ant@1
    #buildFile: 'build.xml' 
    #options: # Optional
    #targets: # Optional
    #publishJUnitResults: true 
    #testResultsFiles: '**/TEST-*.xml' # Required when publishJUnitResults == True
    #testRunTitle: # Optional
    #codeCoverageToolOptions: 'None' # Optional. Options: none, cobertura, jaCoCo
    #codeCoverageClassFilesDirectories: '.' # Required when codeCoverageToolOptions != None
    #codeCoverageClassFilter: # Optional. Comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.*,+:org.*,*.*
    #codeCoverageSourceDirectories: # Optional
    #codeCoverageFailIfEmpty: false # Optional
    #antHomeDirectory: # Optional
    #javaHomeOption: 'JDKVersion' # Options: jDKVersion, path
    #jdkVersionOption: 'default' # Optional. Options: default, 1.11, 1.10, 1.9, 1.8, 1.7, 1.6
    #jdkUserInputDirectory: # Required when javaHomeOption == Path
    #jdkArchitectureOption: 'x64' # Optional. Options: x86, x64


Argument Description
Ant Build File

Relative path from the repository root to the Ant build file.

For more information about build files, see Using Apache Ant.


Options that you want to pass to the Ant command line.

You can provide your own properties (for example, -DmyProperty=myPropertyValue) and also use built-in variables (for example, -DcollectionId=$(system.collectionId)). Alternatively, the built-in variables are already set as environment variables during the build and can be passed directly (for example, -DcollectionIdAsEnvVar=%SYSTEM_COLLECTIONID%).

See Running Apache Ant.


Target(s) for Ant to execute for this build.

See Using Apache Ant Targets.

JUnit Test Results
Publish to Azure Pipelines/TFS Select this option to publish JUnit test results produced by the Ant build to Azure Pipelines or your on-premises Team Foundation Server. Each test result file that matches Test Results Files is published as a test run.
Test Results Files Test results files path. Wildcards can be used. For example, */TEST-.xml for all xml files whose name starts with TEST-."
Test Run Title Assign a title for the JUnit test case results for this build.
Code Coverage
Code Coverage Tool

Select the code coverage tool you want to use.

If you are using the Microsoft-hosted agents, then the tools are set up for you. If you are using on-premises Windows agent, then if you select:

  • JaCoCo, make sure jacocoant.jar is available in lib folder of Ant installation. See JaCoCo.
  • Cobertura, set up an environment variable COBERTURA_HOME pointing to the Cobertura .jar files location. See Cobertura.

After you select one of these tools, the following arguments appear.

Class Files Directories

Specify a comma-separated list of relative paths from the Ant build file to the directories that contain your .class files, archive files (such as .jar and .war). Code coverage is reported for class files present in the directories. Directories and archives are searched recursively for class files. For example: target/classes,target/testClasses.

Class Inclusion/Exclusion Filters

Specify a comma-separated list of filters to include or exclude classes from collecting code coverage. For example: +:com.,+:org.,

Source Files Directories

Specify a comma-separated list of relative paths from the Ant build file to your source directories. Code coverage reports will use these paths to highlight source code. For example: src/java,src/Test.

Set ANT_HOME Path If set, overrides any existing ANT_HOME environment variable with the given path.
Set JAVA_HOME by JDK Version Choose which JDK level will be used to run Ant. Will attempt to find JDK version and assign JAVA_HOME before running Ant.
Set JAVA_HOME by Path Directory on build agent where the JDK is located.
JDK Architecture Optionally supply the architecture (x86, x64) of the JDK.
Control options

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

I'm having problems. How can I troubleshoot them?

See Troubleshoot Build and Release.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.

I use TFS on-premises and I don't see some of these features. Why not?

Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.