2017-01-10 133 views
4

我想用“Http请求插件”做一个简单的POST请求。我的问题是获取凭据的工作。我已设置全球凭证user:passJenkins的基本身份验证http请求插件

但在我的代码尝试这种

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 

回答

5

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)。

def response = httpRequest authentication: 'credentialsID', url: "http://www.example.com" 

其中credentialsID是凭证在詹金斯的ID::

enter image description here

基本凭证

要使用则可以使用下面的代码詹金斯凭证执行HTTP请求在配置系统> HTTP请求下现在指出不推荐基本/摘要式身份验证并使用Jenkins凭据:

enter image description here

+0

我照你的答案也提到,但我得到的错误 - java.lang.IllegalStateException相同:认证“CredentialsID”不存在了 –

+0

你有存储在詹金斯与凭证ID“CredentialsID”?如果您在Jenkins中查看证书,它将显示一个包含(除其他外)每个存储凭证的名称和ID的表格。这是你想使用的ID字段 –

+0

是的,我已经在Jenkins中创建了一个凭据,就像你在答案中提到的那样,然后我使用该Credetial的ID。我提到的细节有问题 - https://stackoverflow.com/questions/48166066/http-request-using-jenkins-pipeline-job –

4

的凭据Http Request Plugin不是由证书插件,而是在配置系统管理 - > HTTP一样显示在请求图片。