使用 Jenkins http-request-plugin 进行基本身份验证

Basic Auth with Jenkins http-request-plugin

我正在尝试使用 "Http Request Plugin" 发出一个简单的 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 Request Plugin 的凭据不是由凭据插件管理的,而是在配置系统 -> HTTP 请求下管理的,如图所示。

HTTP 请求插件 v1.8.18 now supports credentials in the Credentials Plugin (the HTTP Request Plugin 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 请求下的基本凭据现在声明 Basic/Digest 身份验证已弃用,改为使用 Jenkins 凭据: