Search code examples
azure-devopsant

Azure DevOps "ant not found"


I have self-hosted Windows agent with pre-placed Ant and it is placed under C:\Program Files\ant\ however, when I try to use Ant task:

    - task: Ant@1
      inputs:
        buildFile: 'buildFiles\build.xml'
        publishJUnitResults: false
        antHomeDirectory: 'C:\Program Files\ant\'
        javaHomeOption: 'JDKVersion'

I get error message "Unable to locate executable file: 'ant'" even though the file is there under 'C:\Program Files\ant\bin'. How do I need to define the path in order for the executable to be found?


Solution

    1. I added ANT_HOME as the Windows environment variable and point it to my Ant folder in the self-hosted Windows agent.

    enter image description here

    1. Update PATH variable, add %ANT_HOME%\bin in the self-hosted Windows agent.

    enter image description here

    1. Restart the agent and check the agent Capabilities in project settings- agent pools, I can see ant and ANT_HOME.

    enter image description here

    1. Run the task, it will find the ant.exe.

    enter image description here