Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Auth with Jenkins http-request-plugin

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
like image 974
Torbilicious Avatar asked Jan 10 '17 14:01

Torbilicious


People also ask

What happens when you send POST HTTP request to Jenkins URL?

This plugin sends a HTTP/HTTPS request to a user specified URL. The request is made as a job execution in Jenkins and depending of the HTTP response the job could be marked as failed (configurable). For example, responses such as 404 and 500 could make the job fail.

How do I add credentials to Jenkins plugins?

In Jenkins, select Manage Plugins. Select the Available tab. Select the Credentials Binding checkbox. Click Install without restart or Download now and install after restart.


2 Answers

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:

enter image description here

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

enter image description here

like image 99
Ian A Avatar answered Nov 03 '22 09:11

Ian A


The Credentials for the Http Request Plugin are not managed by the Credentials Plugin but rather under Configure System -> HTTP Request like shown in the picture.

like image 20
Torbilicious Avatar answered Nov 03 '22 10:11

Torbilicious