I am using Ant Script in Jenkins to handle the deployment of my files. What I want to do is to trigger a call to a URL that has the web service. My question is, how can I do that from Ant Script or from within Jenkins?
Thanks in advance, Monte
Go to Manage Jenkins -> Manage Plugins -> Available and search for Ant Plugin . After it's installed, go back to your job configuration and select a new build step Invoke Ant .
Jenkins integrates with multiple build tools such as Maven, Gradle, and Ant. In this video, Jenkins expert Kevin Bowersox demonstrates how to automate project builds with Apache Ant, a basic and very useful addition to any developer's continuous integration toolbox.
To take advantage of the Jenkins Ant plugin, create a freestyle project named 'Apache Ant and Jenkins Build Job Example. ' Run the Jenkins Ant build job and the source code will be pulled from GitHub, the tasks will run, and the application will be compiled, tested and packaged as a WAR file.
Ant's get task can be used to invoke web services, but it restricted to GET operations. Only works for very simple web services
Invoke the unix curl command to call the webservice (See this post for examples)
<target name="invoke-webservice">
<exec executable="curl">
<arg line="-d 'param1=value1¶m2=value2' http://example.com/resource.cgi"/>
</exec>
</target>
Note:
The curl command could also be invoked as a post build action in Jenkins
If you need a cross platform and flexible solution embed groovy script within your build to invoke the web service.
<target name="invoke-webservice">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<groovy>
import static groovyx.net.http.ContentType.JSON
import groovyx.net.http.RESTClient
def client = new RESTClient("http://localhost:5498/")
def response = client.put(path: "parking_tickets",
requestContentType: JSON,
contentType: JSON)
log.info "response status: ${response.status}"
</groovy>
</target>
Use the Groovy Postbuild plugin to invoke the web service.
The ANT HTTP task is an alternative to the groovy task above
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With