我正在尝试使用“Http请求插件”进行简单的POST请求。我的问题是要获得凭据才能正常工作。我已经设置了全局凭证user:pass
。
但是在我的代码中尝试
withCredentials([usernameColonPassword(credentialsId: 'akamai', variable: 'akamai')]) {
def response = httpRequest url: requestUrl, contentType: requestContentType, httpMode: requestHttpMode, requestBody: requestContent, authentication: akamai
echo "Status: ${response.status}\nContent: ${response.content}"
}
结果是
java.lang.IllegalStateException: Authentication 'user:pass' doesn't exist anymore
最佳答案
HTTP请求插件v1.8.18 now supports credentials in the Credentials Plugin(HTTP请求插件v1.8.18 now depends on v2.1.3 of the Credentials Plugin)。
要使用Jenkins凭证执行HTTP请求,可以使用以下代码:
def response = httpRequest authentication: 'credentialsID', url: "http://www.example.com"
其中
credentialsID
是Jenkins中凭据的ID:现在,“配置系统”>“HTTP请求”下的基本凭据表明已弃用基本/摘要身份验证,而改为使用Jenkins凭据:
关于groovy - 使用Jenkins http-request-plugin进行基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41571090/