使用 Jenkins http-request-plugin 进行基本身份验证 [英] Basic Auth with Jenkins http-request-plugin

查看:41
本文介绍了使用 Jenkins http-request-plugin 进行基本身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Http 请求插件"进行简单的 POST 请求.我的问题是让凭据起作用.我已经设置了一个全局凭证,user:pass.

但是在我的代码中尝试这个

withCredentials([usernameColonPassword(credentialsId: 'akamai', 变量: 'akamai')]) {def response = httpRequest url: requestUrl, contentType: requestContentType, httpMode: requestHttpMode, requestBody: requestContent, authentication: akamaiecho "状态: ${response.status}
Content: ${response.content}"}

结果

java.lang.IllegalStateException:身份验证user:pass"不再存在

解决方案

HTTP 请求插件 v1.8.18

配置系统">HTTP 请求"下的基本凭据现在声明基本/摘要式身份验证已弃用并改为使用 Jenkins 凭据:

I am trying to make a simple POST-request with the "Http Request Plugin". My problem is with getting the credentials to work. I have set a global credential, user:pass.

But trying this in my code

withCredentials([usernameColonPassword(credentialsId: 'akamai', variable: 'akamai')]) {

    def response = httpRequest url: requestUrl, contentType: requestContentType, httpMode: requestHttpMode, requestBody: requestContent, authentication: akamai
    echo "Status: ${response.status}
Content: ${response.content}"
}

results in

java.lang.IllegalStateException: Authentication 'user:pass' doesn't exist anymore

解决方案

HTTP Request Plugin 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).

To perform an HTTP request using a Jenkins credential you can use the following code:

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

where credentialsID is the ID of the credentials in Jenkins:

The basic credentials under Configure System > HTTP Request now states that the Basic/Digest Authentication is deprecated and to use Jenkins credentials instead:

这篇关于使用 Jenkins http-request-plugin 进行基本身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆