Jenkins – Setup a simple Ant build project

Jenkins, previously named as Hudson, is a continuous integration tool just like CruiseControl. It has been almost 4 years since i started learning Maven which made me fall in love about best practice. Deployment and testing automation is really fun and finally i got a chance to play it again.

In this article, i would show you how to setup a simple Ant build project in Jenkins. Before we start, please refer to the simple Java project example in the post below.


1. Download and install Jenkins.

2. After the installation, you should be able to visit the Jenkins home page by visiting http://localhost:8080/.

3. Configure Jenkins by clicking Manage Jenkins on the left sidebar and the go to the Configure System page.

4. Setup at least one JDK installation and one Ant installation as well.

5. Now we are ready to move on. On the left menu, add a new job and call it com-eureka. As we are working on a simple Ant build project, select Build a free-style software project.

6. After the job is created, you will be on the job configuration page.

7. Add a new Build step and select Invoke Ant.

8. Select the Ant version which we have already configured it on the Configure System page. We could leave the target blank so it will run the default main target defined in the build.xml.

9. Go the the job directory which is C:\Program Files (x86)\Jenkins\jobs\com-eureka in this example. Create a folder name called workspace.

10. Now copy all the source code to this workspace folder.

11. Now go to the com-eureka job index page and click Build Now.

12. After the build, click the build details and you can also refer to the console output and check if there is any errors on the build script.

Done =)

Reference: Jenkins


29 thoughts on “Jenkins – Setup a simple Ant build project”

  1. hi…i have followed all the steps as shown …but am getting an error:
    Building on master in workspace C:\Program Files\Jenkins\workspace\com-eureka
    FATAL: Unable to find build script at C:\Program Files\Jenkins\workspace\com-eureka\build.xml
    Build step ‘Invoke Ant’ marked build as failure
    Finished: FAILURE


      1. Got the solution…i had copied build.xml in the wrong folder…
        Thanks for a informative post on Jenkins:)…Very helpful for beginners …..


      2. the folder name com-eureka is correct. i forgot why i used this confusing name but that’s what i did as shown in the screenshots.


  2. Could you please explain ANT parameterised build feature in Jenkins…?And how do we set the Environmental variables…?Checked the Jenkins tutorial ,but not very clear on how to implement the same .
    Thanks in Advance.


    1. You can add environmental variables under global properties @ Manage Jenkins -> Configure System.

      For Ant build with parameters, you can add parameters by checking the This build is parameterized checkbox in job configuration page. Let’s say you created a string parameter called ABC, you can use $ABC in the Target or Properties under the Invoke Ant section.


  3. hi..followed the steps as ,mentioned abovde, in the run target am getting an error:Error: Could not find or load main class com.eureka.HelloWorld .Please suggest on what changes are to be done .


  4. In Step no 10 “Now copy all the source code to this workspace folder.”….here “build.xml” file is there,but “src” file is not there.From where we will copy here the “src” file.Kindly let me know.Is this Framework source code of all the packages??


  5. Hi,

    Kindly let me know the solution:-
    I am getting this below error while executing:-

    Started by user anonymous
    Building in workspace C:\Program Files (x86)\Jenkins\jobs\PNM_Framework\workspace
    [workspace] $ cmd.exe /C ‘”C:\software\apache-ant-1.9.4\bin\ant.bat && exit %%ERRORLEVEL%%”‘
    Buildfile: C:\Program Files (x86)\Jenkins\jobs\PNM_Framework\workspace\build.xml


    C:\Program Files (x86)\Jenkins\jobs\PNM_Framework\workspace\build.xml:28: destination directory “C:\Program Files (x86)\Jenkins\jobs\PNM_Framework\workspace\bin” does not exist or is not a directory

    Total time: 0 seconds
    Build step ‘Invoke Ant’ marked build as failure
    Finished: FAILURE


    1. As stated in the error message, at line 28 of the build.xml, the bin folder doesn’t exist or is not a directory.

      have you ever tried to run the ant command in ms-dos? does it work?


      1. Yes Ykyuen……….It’s working fine in ms-dos…..

        My build.xml file is given below:-

        WARNING: Eclipse auto-generated file.
        Any modifications will be overwritten.
        To include a user specific buildfile here, simply create one in the same
        directory with the processing instruction
        as the first entry and export the buildfile again.


    Total time: 21 seconds
    Finished: SUCCESS

    But Not Execute Test Case, Please help me out


  7. Yes……script is executing fine through command prompt(build.xml file is triggering testng.xml file sucseefully).
    While executing through Jenkins error is getting displayed.


  8. Hi… I followed the steps you mentioned ,but got the below error,
    Started by user anonymous
    Building in workspace D:\workspace13\zSendToMe
    [zSendToMe] $ cmd.exe /C ‘”ant.bat D:\workspace13\zSendToMe\build.xml && exit %%ERRORLEVEL%%”‘
    Buildfile: D:\workspace13\zSendToMe\build.xml

    Target “D:\workspace13\zSendToMe\build.xml” does not exist in the project “zSendToMe”.

    Total time: 0 seconds
    Build step ‘Invoke Ant’ marked build as failure
    Finished: FAILURE
    Note:1) I have used “Use custom workspace” option in jenkins cnfiguration and given path D:\workspace13\zSendToMe
    2) build.xml is available in location D:\workspace13\zSendToMe\build.xml.
    3)Ant build is successful when ran the build.xml from eclipse.

    Please help me 😦 .


  9. Hi, am facing bellow error. Kindly do the needful

    FATAL: Cannot find executable from the chosen Ant installation “Ant Task”
    Build step ‘Invoke Ant’ marked build as failure
    Finished: FAILURE


  10. Hi All ,
    My requirement is like – > When even a code checkin happen to Dev branch then that should be merged to QA and deployment should happen without any manual action but incase any failure in the flow then Jankin should trigger a mail to the logged in user or we can specify the e mail id . please help me to start .. Thanks


  11. I am able to start the build and compilation completed with log but I do not see class files getting generated in output folder mentioned


Leave a Reply to Deeps Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.