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 是一款强大的持续集成工具,主要负责自动化软件的构建、测试和部署任务。它的核心功能包括持续构建/测试、RSS/邮件/即时消息通知、Junit/TestNG 测试报告生成、分布式构建支持以及丰富...
### Hudson安装全过程详解 #### 一、前言 Hudson是一款开源持续集成工具,主要用于自动化构建、测试软件项目,支持多种SCM(如Git、SVN等),并且可以通过插件扩展功能。本文将详细介绍Hudson的安装过程,包括JDK...
Hudson 是一个开源的持续集成工具,用于自动化各种软件项目构建、测试和部署等任务。在本教程中,我们将深入探讨如何配置和使用Hudson。 首先,为了运行Hudson,你需要准备以下组件: 1. **Apache Tomcat 7.0 以上...
Hudson是一款开源的持续集成工具,用于自动化各种任务,包括构建、测试和部署软件。本文档将深入探讨Hudson的安装、配置、使用方法以及如何搭建远程自动构建和daily_build系统。 1. **Hudson安装** 安装Hudson通常...
【Hudson平台搭建及使用详解】 Hudson是一个开源的持续集成(CI)服务器,它提供了一种自动化构建、测试和部署软件的解决方案。Hudson以其简单易用和丰富的插件功能而受到赞誉,使得项目管理和配置变得更加高效。...
《Hudson持续集成实战》是一本专注于自动化部署的教程,旨在帮助读者掌握使用Hudson进行持续集成的关键技术和实践策略。Hudson,作为一个开源的持续集成工具,被广泛应用于软件开发过程中,以提升效率,减少错误,并...
Hudson是一款开源的持续集成工具,它允许开发者自动构建、测试和部署软件项目。在敏捷开发环境中,持续集成是至关重要的实践,它可以帮助团队快速发现并修复错误,提高软件质量。"Hudson快速启动和停止脚本"是针对...
很抱歉,根据您提供的文件信息,这显然与"Hudson使用配置说明文档"的主题不相符。压缩包中的文件名称都是音乐曲目,与Hudson这款持续集成工具或相关的配置说明无关。Hudson是一款开源的持续集成服务器,用于自动化...
3.1 插件架构:Hudson的插件基于Maven构建,使用Hudson插件框架,包括核心API、服务提供者接口(SPI)和UI组件。 3.2 创建插件项目:使用Maven的hpi插件生成项目骨架,然后根据需求添加必要的依赖和源代码。 3.3 ...
### Hudson常用插件详解 Hudson,作为一款开源持续集成工具,通过丰富的插件系统,极大地增强了其灵活性和功能性,支持多种源代码管理和构建工具,满足不同开发团队的需求。以下是对部分常用插件的详细说明: ####...
hudson-3.2.2 放在tomcat下直接打开即可
hudson插件加载失败解决方案 本文档将讨论hudson插件加载失败的解决方案,涵盖hudson版本、环境信息、插件安装、Tomcat日志分析、问题排查等方面的知识点。 一、hudson版本信息 hudson版本:hudson-2.2.1.war ...
【集成工具Hudson与Maven2的Hudson安装及配置】 持续集成(Continuous Integration, CI)是一种软件开发实践,强调开发人员频繁地将他们的代码更改集成到主分支,以尽早发现并解决潜在的问题。Hudson是一款开源的...
安装过程包括下载Hudson的最新版本,设置环境变量`HUDSON_HOME`,将`hudson.war`复制到Tomcat的`webapps`目录,并启动Tomcat。完成后,可以通过服务器的IP地址和端口号访问Hudson的Web界面。 在系统管理中,需要...
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 ...