如何从 Ant 脚本或 Jenkins 内部调用 Web 服务? [英] How to call a web service from Ant script or from within Jenkins?
问题描述
我在 Jenkins 中使用 Ant 脚本来处理我的文件的部署.我想要做的是触发对具有 Web 服务的 URL 的调用.我的问题是,我怎样才能从 Ant Script 或 Jenkins 内部做到这一点?
提前致谢,蒙特
选项 1:获取"任务
Ant 的 get task 可用于调用 Web 服务,但它仅限于 GET 操作.仅适用于非常简单的网络服务
选项 2:卷曲
调用 unix curl 命令来调用网络服务(请参阅此 post 示例)
<exec executable="curl"><arg line="-d 'param1=value1¶m2=value2' http://example.com/resource.cgi"/></exec></目标>
注意:
curl 命令也可以作为 Jenkins 中的构建后操作调用
选项 3:Groovy ANT 任务
如果您需要跨平台和灵活的解决方案,请在构建中嵌入 groovy 脚本以调用 Web 服务.
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/><常规>导入静态 groovyx.net.http.ContentType.JSON导入 groovyx.net.http.RESTClientdef client = new RESTClient("http://localhost:5498/")def response = client.put(path: "parking_tickets",请求内容类型:JSON,内容类型:JSON)log.info "响应状态:${response.status}"</groovy></目标>
选项 4:Groovy Jenkins 后期构建
使用 Groovy Postbuild 插件 来调用网络服务.
选项 5:ANT HTTP 任务
ANT HTTP 任务是上述常规任务的替代方案>
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
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
Option 2: curl
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
Option 3: Groovy ANT task
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>
Option 4: Groovy Jenkins post build
Use the Groovy Postbuild plugin to invoke the web service.
Option 5: ANT HTTP task
The ANT HTTP task is an alternative to the groovy task above
这篇关于如何从 Ant 脚本或 Jenkins 内部调用 Web 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!