1

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135
b-lieve
  • 139
  • 1
  • 2
  • 7

1 Answers1

7

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.

Community
  • 1
  • 1
Dave Bacher
  • 15,652
  • 3
  • 63
  • 86
  • 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 Oct 29 '10 at 09:58
  • Just create a XML file that contains all the settings (it is not complicated) and than create a folder with your job name in the Hudson jobs folder. in the job folder you put your XML. That's all. Next time Hudson starts the job will be there. All tools that are based on the remote API, need a running Hudson server. – Peter Schuetze Nov 01 '10 at 14:35