如何使用Jenkins http-request插件和Pipeline在正文中发布JSON数据?

use*_*ser 10 groovy http-request jenkins jenkins-plugins jenkins-pipeline

使用Jenkins的http请求插件的v1.8.10(我正在运行1.643),现在支持在请求中POST一个正文 - 所以这个线程不适用.我想知道如何在Pipeline(v2.1)Groovy脚本中使用此功能?片段生成器不包括这个新字段,所以我没有建立的例子.

片段生成器

我已经尝试了各种方法将JSON数据放入请求体,但我的Tomcat服务器始终返回http 400状态代码: The request sent by the client was syntactically incorrect.

我尝试过的事情:

def toJson = {
    input ->
    groovy.json.JsonOutput.toJson(input)
}
def body = [
    displayName: [
        text: "smoke test"],
    description: [
        text: "for smoke testing"],
    genusTypeId: "type"
]
response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: toJson(body), url: "https://${host}", validResponseCodes: '200'
Run Code Online (Sandbox Code Playgroud)
def body = [
    displayName: [
        text: "smoke test"],
    description: [
        text: "for smoke testing"],
    genusTypeId: "type"
]
response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: body, url: "https://${host}", validResponseCodes: '200'
Run Code Online (Sandbox Code Playgroud)
response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: "{\"displayName\":{\"text\":"smoke test\"},\"description\":{\"text\":\"for smoke testing\"}, \"genusTypeId\":\"type\"}", url: "https://${host}", validResponseCodes: '200'
Run Code Online (Sandbox Code Playgroud)
response = httpRequest consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: "'{\"displayName\":{\"text\":"smoke test\"},\"description\":{\"text\":\"for smoke testing\"}, \"genusTypeId\":\"type\"'}", url: "https://${host}", validResponseCodes: '200'
Run Code Online (Sandbox Code Playgroud)

扫描http-request库代码,似乎设置此标志应该工作.我不知道Pipeline插件/ Jenkins插件是如何工作的,所以我想知道Pipeline - > http-request代码是否考虑了这个新参数?有人能指出我如何使用请求主体使用管道进行POST,或者我需要修改Pipline插件代码来建立连接?