Jenkins管道发送HttpRequest

问题描述 投票:0回答:1

我正在尝试在Jenkins管道中发送HTTP发布请求。我试图在后正文请求中传递变量,但这样做却得到500个异常。

但是当我使用“修订”之类的硬代码时:123456可以正常工作。

我如何在requestbody中传递gitCommit变量

  env.gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()

 httpRequest    acceptType: 'APPLICATION_JSON',
                contentType: 'APPLICATION_JSON',
                consoleLogResponseBody: true,
                customHeaders: [[maskValue: true, name: 'X-Api-Key', value: 'xxxxxxxxxxxx']],
                httpMode: 'POST',
                ignoreSslErrors: true,
                requestBody: '''{
                    "deployment": {
                        "revision": ${gitCommit}
                    }
                }''',
                responseHandle: 'NONE',
                url: 'https://api.newrelic.com/v2/applications/xxxxxxx/deployments.json'
jenkins jenkins-pipeline httprequest newrelic jenkins-groovy
1个回答
0
投票

您是否尝试过$ GIT_COMMIT参数? (如果您在Jenkins中使用Git插件)

© www.soinside.com 2019 - 2024. All rights reserved.