如何从调用Ant脚本或从内部詹金斯Web服务? [英] How to call a web service from Ant script or from within Jenkins?
问题描述
我使用Ant脚本在詹金斯来处理我的文件部署。我想要做的是触发一个呼叫到具有Web服务的URL。我的问题是,我该怎么办,从Ant脚本,或者从内部詹金斯?
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
推荐答案
Ant的得到任务的可用于调用网络服务,但它仅限于GET操作。只适用于非常简单的Web服务
Option 1: "get" task
Ant's get task can be used to invoke web services, but it restricted to GET operations. Only works for very simple web services
调用UNIX的卷曲的命令来调用web服务(见本<一个href=\"http://superuser.com/questions/149329/how-do-i-make-a-post-request-with-the-curl-command-line-tool\">post的例子)
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>
注意:
的卷曲的命令也可以援引作为詹金斯后生成操作
The curl command could also be invoked as a post build action in Jenkins
如果您需要构建中的跨平台和灵活的解决方案嵌入Groovy脚本调用Web服务。
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>
选项4:Groovy的詹金斯后生成
使用 Groovy的Postbuild插件来调用Web服务。
借助 ANT HTTP任务是上述
这篇关于如何从调用Ant脚本或从内部詹金斯Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!