1、hudson API create job
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
String hudson = "http://10.20.157.179:8080/hudson/";
File configFile = new File("config.xml");
put(client, hudson, "test", configFile);
}
private static void put(HttpClient client, String hudsonBaseURL, String jobName, File configFile)
throws IOException,
HttpException {
PostMethod postMethod = new PostMethod(hudsonBaseURL + "/createItem?name=" + jobName);
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "sfhudson");
client.getState().setCredentials(new AuthScope("10.20.157.179", 8080), defaultcreds);
postMethod.setRequestHeader("Content-type", "application/xml; charset=ISO-8859-1");
postMethod.setRequestBody(new FileInputStream(configFile));
postMethod.setDoAuthentication(true);
try {
int status = client.executeMethod(postMethod);
System.out.println(status + "\n" + postMethod.getResponseBodyAsString());
} finally {
postMethod.releaseConnection();
}
}
2、update hudson job
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
String hudson = "http://10.20.157.179:8080/hudson/";
File configFile = new File("config.xml");
put(client, hudson, "test", configFile);
}
private static void put(HttpClient client, String hudsonBaseURL, String jobName, File configFile)
throws IOException,
HttpException {
PostMethod postMethod = new PostMethod(hudsonBaseURL + "/job/" + jobName + "/config.xml");
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "sfhudson");
client.getState().setCredentials(new AuthScope("10.20.157.179", 8080), defaultcreds);
postMethod.setRequestHeader("Content-type", "application/xml; charset=ISO-8859-1");
postMethod.setRequestBody(new FileInputStream(configFile));
postMethod.setDoAuthentication(true);
try {
int status = client.executeMethod(postMethod);
System.out.println(status + "\n" + postMethod.getResponseBodyAsString());
} finally {
postMethod.releaseConnection();
}
}
3、copy hudson job
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
String hudson = "http://10.20.157.179:8080/hudson/";
File configFile = new File("config.xml");
put(client, hudson, "test", configFile);
}
private static void put(HttpClient client, String hudsonBaseURL, String jobName, File configFile)
throws IOException,
HttpException {
PostMethod postMethod = new PostMethod(hudsonBaseURL + "/createItem");
NameValuePair n1 = new NameValuePair("name", "copyNew");
NameValuePair n2 = new NameValuePair("mode", "copy");
NameValuePair n3 = new NameValuePair("from", jobName);
postMethod.setQueryString(new NameValuePair[] { n1, n2, n3 });
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "sfhudson");
client.getState().setCredentials(new AuthScope("10.20.157.179", 8080), defaultcreds);
postMethod.setRequestHeader("Content-type", "application/xml; charset=ISO-8859-1");
postMethod.setRequestBody(new FileInputStream(configFile));
postMethod.setDoAuthentication(true);
try {
int status = client.executeMethod(postMethod);
System.out.println(status + "\n" + postMethod.getResponseBodyAsString());
} finally {
postMethod.releaseConnection();
}
}
4、delete job
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
String hudson = "http://10.20.157.179:8080/hudson/";
put(client, hudson, "copyNew");
}
private static void put(HttpClient client, String hudsonBaseURL, String jobName) throws IOException, HttpException {
PostMethod postMethod = new PostMethod(hudsonBaseURL + "/job/" + jobName + "/doDelete");
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "sfhudson");
client.getState().setCredentials(new AuthScope("10.20.157.179", 8080), defaultcreds);
postMethod.setDoAuthentication(true);
try {
int status = client.executeMethod(postMethod);
System.out.println(status + "\n" + postMethod.getResponseBodyAsString());
} finally {
postMethod.releaseConnection();
}
}
5、enable disable job
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
String hudson = "http://10.20.157.179:8080/hudson/";
put(client, hudson, "test");
}
private static void put(HttpClient client, String hudsonBaseURL, String jobName) throws IOException, HttpException {
PostMethod postMethod = new PostMethod(hudsonBaseURL + "/job/" + jobName + "/disable");
client.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin", "sfhudson");
client.getState().setCredentials(new AuthScope("10.20.157.179", 8080), defaultcreds);
postMethod.setDoAuthentication(true);
try {
int status = client.executeMethod(postMethod);
System.out.println(status + "\n" + postMethod.getResponseBodyAsString());
} finally {
postMethod.releaseConnection();
}
}
分享到:
相关推荐
Hudson安装与使用,Hudson配置,Hudson插件Hudson安装与使用,Hudson配置,Hudson插件Hudson安装与使用,Hudson配置,Hudson插件Hudson安装与使用,Hudson配置,Hudson插件Hudson安装与使用,Hudson配置,Hudson插件...
hudson-3.2.2 放在tomcat下直接打开即可
For Production use, Hudson 3.3.1 from the Eclipse Foundation is now available. This WAR file is suitable for any O/S. We recommend that users of 3.0, 3.1, 3.2 or 3.3.0 upgrade to this release. his ...
hudson安装及其配置 hudson平台搭建及使用 Hudson使用参考手册 关于hudson远程自动构建发布 使用hudson_搭建daily_build_系统
hudson 中文操作手册 hudson 中文操作手册 hudson 中文操作手册
hudson持续集成包hudson持续集成包
如何在电脑上配置Hudson并通过Hudson进行持续集成的测试!
Hudson 是一个可扩展的持续集成引擎。 主要用于: 1.持续、自动地构建/测试软件项目,如CruiseControl与DamageControl。 2.监控一些定时执行的任务。 Hudson拥有的特性包括: •易于安装-只要把hudson.war部署到...
Hudson 是一种革命性的开放源码 CI 服务器,它从以前的 CI 服务器吸取了许多经验教训。Hudson 最吸引人的特性之一是它很容易配置:很难找到更容易设置的 CI 服务器,也很难找到开箱即用特性如此丰富的 CI 服务器。...
非常简单的Hudson安装步骤,简洁可行,还不用积分哦
hudson.freemarker_ide_0.9.14 hudson.freemarker_ide_0.9.14 hudson.freemarker_ide_0.9.14 hudson.freemarker_ide_0.9.14 hudson.freemarker_ide_0.9.14
这是一个用hudson+maven+svn完成持续开发的详细教程。
Hudson常用插件说明
Hudson持续集成实战 自动化部署教程
hudson.war是基于Java研发的一款持续集成工具的安装包,hudson是一个可以扩展的持续集成引擎,主要是用它来监控一些定时执行的任务、持续、自动地构建/测试软件项目,有需要的欢迎下载使用。 hudson下载,放在tomcat...
集成工具hudson与maven2的Hudson 安装及配置
hudson平台搭建及使用hudson平台搭建及使用
hudson使用配置说明文档,内含详细截图及其配置说明
hudson2.2.0的war包。 我只能上传小于50MB的文件所以分了两个压缩包。这是第二个包
Hudson平台搭建及使用,作为项目管理及配置来说,用它不错