【发布时间】:2022-07-29 21:27:38
【问题描述】:
我在从 Jenkins 管道中访问声纳 api 时收到 401 错误,但从邮递员那里我得到了具有相同凭据的相同 URL 的正确响应,但是在 Jenkins 中我得到以下错误
Response Code: HTTP/1.1 401
20:26:38 Response:
这是我的网址
http://www.sonarqube.com/api/measures/component?componentKey=projectKey&metricKeys=major_violations,info_violations,blocker_violations,minor_violations,critical_violations&includetrends=true&resolved=false
我已经尝试了这两种方法(如下),但没有什么对我有用。
def getJSONResp(url,credentials) {
echo(credentials)
def content
String auth = credentials.bytes.encodeBase64().toString()
def json = httpRequest consoleLogResponseBody: true,
httpMode: 'GET',
responseHandle: 'NONE',
url: url,
customHeaders:[[name:'Authorization', value:"Basic ${auth}"]]
content = readJSON text: json.content
return content
}
def getJSONResp(url,credentials) {
echo(credentials)
def content
def json = httpRequest consoleLogResponseBody: true,
httpMode: 'GET',
responseHandle: 'NONE',
url: url,
customHeaders:[[name:'Authorization', value:"Basic ${credentials}"]]
content = readJSON text: json.content
return content
}
谁能帮我解决这个问题。
【问题讨论】:
标签: api jenkins jenkins-pipeline jenkins-plugins sonarqube-api