Jenkinsのhttp-requestプラグインのv1.8.10(私は1.643を実行しています)では、要求にボディをPOSTする機能が追加されました。このthreadは適用されません。私はパイプライン(v2.1)のGroovyスクリプトでこの機能を使用する方法を知りたいですか?スニペットジェネレータにはこの新しいフィールドが含まれていないので、私はビルドする例はありません。Jenkinsのhttp-requestプラグインとPipelineを使用して本文にJSONデータをPOSTする方法は?
私がリクエストボディにJSONデータを取得するためのさまざまな方法を試してみましたが、私のTomcatサーバーは常にHTTP 400ステータスコードを返します:
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'
を:私が試してみました
The request sent by the client was syntactically incorrect.
物事を
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'
ライブラリコードをスキャン
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'
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'
、それはこのフラグは動作するはずの設定のように思えます。私はPipelineプラグイン/ Jenkinsプラグインのしくみを知らないので、Pipeline - > http-request codeがこの新しいパラメータを扱うのだろうか?誰かが、リクエストボディがPipelineで動作するようにPOSTを行う方法、またはPiplineプラグインのコードを変更して接続する必要がある場所を教えてもらえますか?
あなたはそのための 'curl'を使用してみましたか?シェル内で簡単にテストできるという利点があります。 –
私はそれを試していませんでした...私は応答オブジェクトを引き込み操作する必要があります。そして、それをカールとするのが難しいどこかで読んでいたので、実行可能な選択肢ではないと思いました。 – user