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/.
jenkins-simple-ant-build-project-1
 

3. Configure Jenkins by clicking Manage Jenkins on the left sidebar and the go to the Configure System page.
jenkins-simple-ant-build-project-2
 

4. Setup at least one JDK installation and one Ant installation as well.
jenkins-simple-ant-build-project-3
 

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.
jenkins-simple-ant-build-project-4
 

6. After the job is created, you will be on the job configuration page.
jenkins-simple-ant-build-project-5
 

7. Add a new Build step and select Invoke Ant.
jenkins-simple-ant-build-project-6
 

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.
jenkins-simple-ant-build-project-7
 

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.
jenkins-simple-ant-build-project-8
 

10. Now copy all the source code to this workspace folder.
jenkins-simple-ant-build-project-9
 

11. Now go to the com-eureka job index page and click Build Now.
jenkins-simple-ant-build-project-10
 

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

    Like

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

        Like

      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.

        Like

  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.

    Like

    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.

      Like

  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 .

    Like

  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??

    Like

  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

    compile:

    BUILD FAILED
    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

    Like

    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?

      Like

      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.
        –>

        Like

  6. BUILD SUCCESSFUL
    Total time: 21 seconds
    Finished: SUCCESS

    But Not Execute Test Case, Please help me out

    Like

  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.

    Like

  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

    BUILD FAILED
    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 😦 .

    Like

  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

    Like

  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

    Like

  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

    Like

Leave a comment

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