How to invoke Ant in a Jenkins Groovy Pipeline

user5917011 picture user5917011 · Dec 29, 2016 · Viewed 16.8k times · Source

I have created a Jenkins Pipeline job. In this job I want to do the build using Ant. I have configured the Ant variable in Manage **Jenkins > Global Tool Configuration** as Ant1.9.1= D:\path_to_hybris\hybris\bin\platform\apache-ant-1.9.1.

In a freestyle jenkins Job, I know that the build.xml location can be specified as in the below screenshot: enter image description here

but I am unable to understand how to specify the ant groovy script beyond this point, especially where can we mention the path to build.xml file:

def antHome = tool 'Ant1.9.1'
????
????

Answer

Khalid Bin Huda picture Khalid Bin Huda · May 30, 2018

you can use ant wrapper in Jenkins`s pipeline groovy script.

withAnt(installation: 'LocalAnt') {
// some block
   sh "ant build"
//for windows 
   bat "ant build"
}

Remember to configure the ant tool in the Jenkins "Global Tool Configuration" with the same name "LocalAnt".