Jenkins Remote Job Creation via Apache HttpClient or HttpUrlConnection

76 views
Skip to first unread message

vinodhi...@gmail.com

unread,
Apr 6, 2015, 5:28:02 AM4/6/15
to jenkin...@googlegroups.com
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+clients

Could you please help me?

Thanks in advance!

vinodhi...@gmail.com

unread,
Apr 6, 2015, 5:40:31 AM4/6/15
to jenkin...@googlegroups.com
Hello All,

My Jenkins is over  HTTPS.

Thanks
Reply all
Reply to author
Forward
0 new messages