Hello All,
I am using Apache HTTPClient to create remote job in Jenkins. My Jenkins is running behind Apache.
I get the error message : "HTTP/4.1 401 Authorization Required" when I run the below code. I could login into Jenkins and create job via browser. But when I try to create job via Apache HTTP Client, it is failing. Please find my code here :
String input = getConfigJobXML();
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(postUrl);
httpPost.setEntity(new StringEntity(input,ContentType.APPLICATION_ATOM_XML));
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials(username, password);
httpPost.addHeader(new BasicScheme().authenticate(creds, httpPost, null));
CloseableHttpResponse response = client.execute(httpPost);
System.out.println(response.getStatusLine());
Header[] allHeaders = response.getAllHeaders();
for (Header iterable_element : allHeaders) {
System.out.println(iterable_element);
}
System.out.println(response.getStatusLine().getStatusCode());
client.close();
My output is :
HTTP/1.1 401 Authorization Required
Date: Mon, 06 Apr 2015 09:17:56 GMT
WWW-Authenticate: NTLM
Content-Length: 401
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
401
I tried the code at below site. But, remote job creation failed.
https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clientsCould you please help me?
Thanks in advance!