3

I'm trying to copy an existing Jenkins job and rename it in the same folder using Groovy. In addition, I would like to do a search and replace a word within git "polling ignores commits in certain paths" message box.

Is it possible and if so how can it be done?

James
  • 875
  • 2
  • 15
  • 24

1 Answers1

3

I was needing to solve a similar problem, and I found this groovy sample for copying all the jobs in a view.

import hudson.model.*

def viewName = "product-build-dev"
def search = "-dev"
def replace = "-prod"

def view = Hudson.instance.getView(viewName)

/* now you copy all jobs of the view copy all projects of a view */
for(item in view.getItems()) {

  /* create the new project name */
  newName = item.getName().replace(search , replace)

  /* now copy the job */
  def job = Hudson.instance.copy(item, newName)
  job.save()

}

I just realized I didn't answer the whole question. Looking...

karel
  • 5,489
  • 46
  • 45
  • 50
Rob Fagen
  • 774
  • 1
  • 8
  • 24