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
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
LikeLike
Did you create the build.xml in C:\Program Files\Jenkins\workspace\com-eureka?
LikeLike
Got the solution…i had copied build.xml in the wrong folder…
Thanks for a informative post on Jenkins:)…Very helpful for beginners …..
LikeLike
You are welcome~
LikeLike
…workspace\com\eureka
LikeLike
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.
LikeLike
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.
LikeLike
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.
LikeLike
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 .
LikeLike
I think it’s not related to the Jenkins setup. Please check my reply in another post.
LikeLike
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??
LikeLike
The src folder should contain your project source code.
Here is an example which u could follow.
Apache Ant – A simple Ant build project
LikeLike
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
LikeLike
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?
LikeLike
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.
–>
LikeLike
Please follow the syntax highlight to paste your code.
Can u check if Jenkins has the permission to write files on the workspace folder? Windows may have problems to run Jenkins.
LikeLike
BUILD SUCCESSFUL
Total time: 21 seconds
Finished: SUCCESS
But Not Execute Test Case, Please help me out
LikeLike
Did your ant target include running the test case?
LikeLike
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.
LikeLike
no idea what happens. did u install jenkins as a service as suggested by the jenkins official website?
Installing Jenkins
LikeLike
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 😦 .
LikeLike
like the previous comment, it seems that the problem is related to running jenkins on windows. i haven’t tried that before. u’d better consult the jenkins community.
Asking for Help
LikeLike
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
LikeLike
i am not able to create the folder workspace as mention in the steps
LikeLike
Thank you very much ! You have cleared out the difference between them.
LikeLike
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
LikeLike
Can you please help me to find out, where to paste my app in Mac machine?
LikeLike
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
LikeLike