jenkins自动构建
来源:互联网 发布:知乎年度吐槽精选10 编辑:程序博客网 时间:2024/05/20 06:22
参考这个https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients
使用HttpClient触发jenkins自动构建:
import java.io.IOException;import java.net.URI;import org.apache.http.HttpHost;import org.apache.http.HttpResponse;import org.apache.http.auth.AuthScope;import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.client.AuthCache;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.CredentialsProvider;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.protocol.HttpClientContext;import org.apache.http.impl.auth.BasicScheme;import org.apache.http.impl.client.BasicAuthCache;import org.apache.http.impl.client.BasicCredentialsProvider;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClients;import org.apache.http.util.EntityUtils;public class JenkinsScraper { public static void main(String[] args) throws ClientProtocolException, IOException { String string = scrape("http://172.172.210.66:8080/job/firstapp/build","username","password"); System.out.println(string); } public static String scrape(String urlString, String username, String password) throws ClientProtocolException, IOException { URI uri = URI.create(urlString); HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put(host, basicAuth); CloseableHttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); HttpGet httpGet = new HttpGet(uri); // Add AuthCache to the execution context HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); HttpResponse response = httpClient.execute(host, httpGet, localContext); return EntityUtils.toString(response.getEntity()); }}
0 0
- Jenkins自动构建
- C# Jenkins 自动构建
- jenkins 自动构建项目
- jenkins 自动构建
- jenkins自动构建
- Jenkins-android自动构建
- Jenkins-iOS自动构建
- Jenkins-iOS自动构建
- SpringBoot Jenkins自动构建
- Jenkins实现自动构建
- Jenkins SVN自动构建
- Ant 整合Jenkins自动构建
- Jenkins自动构建的方法
- git+jenkins自动构建一
- git+jenkins自动构建二
- Git+Jenkins之自动构建
- Jenkins自动构建的方法
- 基于Jenkins的自动构建系统开发
- 抗洪佚事
- 看贴不回就是犯罪
- java对redis的基本操作
- Codeforces 708C 树形DP
- 喝酒偶得
- jenkins自动构建
- 请你出列
- 今天我思维特别缜密,结果发现:
- poj 1122
- 东方红
- RasGetConnectStatus
- 给他人不同人
- 液氨泄漏
- 拔牙记