Groovy 使用Jenkins http请求插件进行基本身份验证

Groovy 使用Jenkins http请求插件进行基本身份验证,groovy,jenkins-plugins,jenkins-pipeline,Groovy,Jenkins Plugins,Jenkins Pipeline,我试图用“Http请求插件”发出一个简单的POST请求。我的问题是如何让证书发挥作用。我已经设置了一个全局凭证,用户:pass 但是在我的代码中尝试这个 withCredentials([usernameColonPassword(credentialsId: 'akamai', variable: 'akamai')]) { def response = httpRequest url: requestUrl, contentType: requestContentType, htt

我试图用“Http请求插件”发出一个简单的POST请求。我的问题是如何让证书发挥作用。我已经设置了一个全局凭证,
用户: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请求插件的凭据不由凭据插件管理,而是在Configure System->Http请求下管理,如图所示


HTTP请求插件v1.8.18(HTTP请求插件v1.8.18)

要使用Jenkins凭据执行HTTP请求,可以使用以下代码:

def response = httpRequest authentication: 'credentialsID', url: "http://www.example.com"
其中,
credentialsID
是Jenkins中凭证的ID:

“配置系统”>“HTTP请求”下的“基本凭据”现在表示,基本/摘要身份验证已被弃用,改为使用Jenkins凭据:


我做了与您在回答中提到的相同的操作,但我得到了错误-java.lang.IllegalStateException:身份验证'CredentialsID'不再存在您是否有ID为“CredentialsID”的凭证存储在Jenkins中?如果您在Jenkins中查看凭证,它将显示一个表,其中包含(除其他外)每个存储凭证的名称和ID。这是你想要使用的ID字段是的,正如你在回答中提到的,我在Jenkins中创建了一个凭证,然后我使用该凭证的ID。我已经提到了问题中的细节-Jenkins不提供创建基本身份验证凭据的功能。您创建了什么类型的凭据来处理不推荐使用的便笺?如果您仍然需要传递基本身份验证的“明文”凭据(例如,您将其存储在Vault中,而不是存储在Jenkins凭据中),您可以像在中一样制作授权标头。另请注意,
customHeaders
参数现在接受
maskValue
以隐藏username:password的base64,请参阅以了解更多信息。现在不推荐使用此参数。