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}\nContent: ${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:
来源:https://stackoverflow.com/questions/41571090/basic-auth-with-jenkins-http-request-plugin