Well the integration of any CI tool with ANT is fairly common in the industry. It’s a part of DevOps. Here we are working on two things Jenkins and ANT. The Requirement of this technique is very important because it will set a particular value in your ANT build file without doing hardcoded you can pass whatever value on the run time and your ANT build file will stay remain as it is.
Jenkins offers a simple way to set up a continuous integration or continuous delivery (CI/CD) environment for almost any combination of languages and source code repositories using pipelines, as well as automating other routine development tasks. While Jenkins doesn’t eliminate the need to create scripts for individual steps, it does give you a faster and more robust way to integrate your entire chain of build, test, and deployment tools than you can easily build yourself.
Apache Ant (“Another Neat Tool”) is a Java library used for automating build processes for Java applications. Additionally, Ant can be used for building non-Java applications. It was initially part of the Apache Tomcat codebase and was released as a standalone project in 2000.
In many aspects, Ant is very similar to Make, and it’s simple enough so anyone can start using it without any particular prerequisites. Ant build files are written in XML, and by convention, they’re called build.xml.
Different phases of a build process are called “targets”.
Here is the sample of the ant build file.
<delete dir="classes" />
<mkdir dir="classes" />
<javac srcdir="src"destdir="classes" />
<mkdir dir="jar" />
<java jar="jar/HelloWorld.jar"fork="true" />
Now let’s say you in the above ant build you want this fork value to be false or true according to your scenario and you don’t want to hardcode so for this we can pass this value on our run time from Jenkins.
To do this we have to add a property tag in our ANT build file. Now a property tag will look like this:-
<property name="abc" value="src"/>
The <property> tag should directly comes under the <project>. It won’t go inside under the target or any other tags. Also, the property value is up to you, if you want you can give a value for a default run so when you will not anything on runtime then that default value works. I have passed “src” here.