Thanks Mark. Reading the source code git plugin I've been able to modify the git repository address. You were right there was DataBoundConstructor to do it, its name is UserRemoteConfig.
Iñigo On Friday, 18 March 2016 22:27:44 UTC+1, Mark Waite wrote: > > Since the job uses the remote repository address which is stored inside > the repository, I suggested that you use JGit to modify the job definition > in the repository, then rely on the plugin to read the definition from the > repository. > > Alternately, you could look at the source code of the git plugin and the > git client plugin, to see if there is a convenient programming interface. > Since the repository address can be set from the user interface, there is > likely a DataBoundConstructor and/or DataBoundSetter which can set the > repository address and repository name. > > Mark Waite > > On Fri, Mar 18, 2016 at 3:06 PM Iñigo Telleria <[email protected] > <javascript:>> wrote: > >> As far as I've understood JGit is to manage a local or remote repostiry. >> However, what I need is to modify remote repository address of a job. >> >> For example, a job's repository url is http://domain.com/project.git. >> With the plugin I'm implementing I want to replace that address with >> another one, http://newdomain.com/newproject.git. >> >> To get this, I've tried with the snippet I've included above but it >> doesn't work. Any idea? >> >> >> On Friday, 18 March 2016 19:12:32 UTC+1, Mark Waite wrote: >> >>> You might try the instructions at >>> http://stackoverflow.com/questions/12799573/add-remote-via-jgit >>> >>> On Fri, Mar 18, 2016 at 7:14 AM Iñigo Telleria <[email protected]> wrote: >>> >> Hi, >>>> >>>> I'm developing a Jenkins plugin which copies a job (template-job) and >>>> changes some data. >>>> >>>> To do so, I've written this code in a plugin: >>>> >>>> MavenModuleSet template = (MavenModuleSet) jenkins.getItem( >>>> "template-job"); >>>> MavenModuleSet newJob = (MavenModuleSet) jenkins.copy((TopLevelItem) >>>> template, "new-job-name"); >>>> >>>> GitSCM gitScm = (GitSCM) newJob.getScm(); >>>> List<RemoteConfig> repositories = gitScm.getRepositories(); >>>> >>>> if (repositories.size() != 1) { >>>> throw new IllegalStateException("Just one repository was expected and >>>> there are " + repositories.size()); >>>> } >>>> >>>> RemoteConfig repository = repositories.get(0); >>>> repository.removeURI(new URIish("${REPOSITORY_URL}")); >>>> String newUrl = "http://domain.com/project.git" >>>> repository.addURI(new URIish(url)); >>>> >>>> This code creates a new job based on template-job and it has a new >>>> name. However, I can't change its git's repository url. >>>> >>>> Have I missed something? Can somebody give me a clue? >>>> >>>> Iñigo >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Jenkins Users" group. >>>> >>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>> >>> >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/jenkinsci-users/cb67d0da-3d96-478b-a024-d79445f48b7b%40googlegroups.com >>>> >>>> <https://groups.google.com/d/msgid/jenkinsci-users/cb67d0da-3d96-478b-a024-d79445f48b7b%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Jenkins Users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/jenkinsci-users/b42df2ac-e7c6-4c00-825f-491aa6b6ee12%40googlegroups.com >> >> <https://groups.google.com/d/msgid/jenkinsci-users/b42df2ac-e7c6-4c00-825f-491aa6b6ee12%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1346324a-f829-4482-b88f-ddca143f109b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
