Created
June 6, 2014 08:36
-
-
Save ehartmann/f5b9cb64d585496f6e49 to your computer and use it in GitHub Desktop.
Jenkins with http commons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL jenkinsURL = new URL(config.getJenkinsUrl()); | |
// Create AuthCache instance | |
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); | |
credentialsProvider.setCredentials( | |
new AuthScope(jenkinsURL.getHost(), jenkinsURL.getPort(), "realm"), | |
new UsernamePasswordCredentials(config.getJenkinsUsername(), config.getJenkinsPassword()) | |
); | |
AuthCache authCache = new BasicAuthCache(); | |
BasicScheme basicAuth = new BasicScheme(); | |
authCache.put(new HttpHost(jenkinsURL.getHost()), basicAuth); | |
HttpClientContext context = HttpClientContext.create(); | |
context.setCredentialsProvider(credentialsProvider); | |
context.setAuthCache(authCache); | |
CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build(); | |
HttpPost post = new HttpPost(Configuration.getConfig().getJenkinsUrl() + "script/"); | |
List<NameValuePair> nvps = new ArrayList<>(); | |
nvps.add(new BasicNameValuePair("script", nodeConfig.getGroovyScript())); | |
post.setEntity(new UrlEncodedFormEntity(nvps)); | |
try { | |
HttpResponse response = httpclient.execute(post, context); | |
LOG.warn(IOUtils.toString(response.getEntity().getContent())); | |
} catch (HttpResponseException ex) { | |
LOG.error("Http Error", ex); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment