tags:

views:

37

answers:

1

Dear developpers, I need your help !

I want to know how do Hudson generate a job's config.xml?

I explain: I want to add in my application a hudson-like build tool, to do this, a user will have, like in Hudson's GUI, define some parameters like path to jdk, where the pom.xml is stored, etc... and then the config.xml for this job is generated.

Once i will have the config.xml for this job, i will create and build it.

I tried to search for Hudson's API, but it's all about creating a job, building, deleting.. but no way to give it parameters (personalize it). This is a "create" code sample:

private void put(HttpClient client, String hudsonBaseURL,String jobName ,File configFile) throws IOException, HttpException {
    PostMethod postMethod = new PostMethod(hudsonBaseURL+ "/createItem?name=" + jobName);
    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("Projet existe déjà\n"+status + "\n"+ postMethod.getResponseBodyAsString());
    } finally {
        postMethod.releaseConnection();
    }
}

This method requires the config.xml to create a job.

I'm now trying to see the content of the hudson.war, inside its classes, but i have to say that this is not easy.

I wish i was clear.

Any idea would be welcome.

Nacef.

A: 

I recommend using Hudson's remote API for automating creation of a job.

Have a look at http://your.hudson.server/api. Hudson will return HTML documentation for the remote API. Under Create Job you'll see that you can POST a config.xml to a Hudson URL in order to create a job. You should be able to create a template job manually, then use that config.xml as a template in your automated system.

As described in this previous answer, job configuration can be found in HUDSON_HOME/jobs/[name]/config.xml.

Dave Bacher
Thank you Dave for your answer, i have another question, is it possible to create a Hudson Job from Java Code without having Hudson running, i downloaded Hudson's source and tried running classes onto Eclipse but i'm encountring several problems.
b-lieve