如何从詹金斯工作流程中调用REST [英] How to call REST from jenkins workflow
问题描述
我想知道如何从(时髦的)Jenkins工作流脚本中调用REST API.我可以执行"sh'curl -X POST ...'"-它可以工作,但是将请求构建为curl命令比较麻烦,并且处理响应会变得很复杂.我希望使用本机Groovy HTTP客户端进行groovy编程-我应该从哪一个开始?由于该脚本是在Jenkins中运行的,因此存在将所有必需的依赖项jar复制到Jenkins上的groovy安装中的步骤,因此希望轻量级一些.
I wonder how to call REST API from a (groovy) Jenkins workflow script. I can execute "sh 'curl -X POST ...'" - it works, but building the request as a curl command is cumbersome and processing the response gets complicated. I'd prefer a native Groovy HTTP Client to program in groovy - which one should I start with? As the script is run in Jenkins, there is the step of copying all needed dependency jars to the groovy installation on Jenkins, so something light-weight would be appreciated.
推荐答案
有一个内置的可用步骤,该步骤正在使用Jenkins HTTP请求插件进行http请求.
There is a built in step available that is using Jenkins HTTP Request Plugin to make http requests.
插件: https://wiki.jenkins-ci.org/display/JENKINS/HTTP + Request + Plugin
来自插件github页面的示例:
Example from the plugin github page:
def response = httpRequest "http://httpbin.org/response-headers?param1=${param1}"
println('Status: '+response.status)
println('Response: '+response.content)
这篇关于如何从詹金斯工作流程中调用REST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!