Buddy
Buddy

Reputation: 152

How to dynamically set the local maven repo for a jenkins job

I'm trying to create a jenkins job using the Jenkins remote access API[1]. What I want to achieve is, I want to specify the local maven repository for the job(instead of using global repository), using the job configuration(config.xml) which I send to the create job API. How can I achieve that? What are the xml attributes that I should have added(or changed)?

[1] https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

Upvotes: 0

Views: 827

Answers (3)

Buddy
Buddy

Reputation: 152

We can define local maven repository for a particular job, by specifing the localRepository element in job configuration. By default there are three options supported out of the box by jenkins.

  1. Default repository(~/.m2/repository)

    <localRepository class="hudson.maven.local_repo.DefaultLocalRepositoryLocator"/>
    
  2. Local to the Executor

    <localRepository class="hudson.maven.local_repo.PerExecutorLocalRepositoryLocator"/>
    
  3. Local to the workspace

    <localRepository class="hudson.maven.local_repo.PerJobLocalRepositoryLocator"/>
    

So if you want to define your own local repository locator based on build parameters or build information, you can extend the hudson.maven.local_repo.LocalRepositoryLocator class and implement your own logic and specify it under localRepositoryelement in the job configuration. ex:

<localRepository class="org.sample.MyOwnLocalRepositoryLocator"/>

Upvotes: 0

Christopher Orr
Christopher Orr

Reputation: 111555

Manually configure a job as you want it, then visit the URL $JENKINS/job/$JOB/config.xml — there you will be able to see which XML tags are required for your desired configuration.

Upvotes: 0

Stan
Stan

Reputation: 3461

According to API its something like that:

curl -X POST -H "Content-Type:application/xml" -d @config.xml "http://JENKINS_HOST/createItem?name=Some_Job_Name"

Upvotes: 0

Related Questions