Jenkinsは既存の構築タスクスクリプトを一括コピーする

1464 ワード

多くのテスト構築タスクを新規作成した後、生産構築タスクを繰り返すのは面倒で、ネット上でスクリプトテストに成功し、システムスクリプトの
import hudson.model.*
	// view
	def str_view = "01--test"
	// view
	def str_new_view = "02--prod"
	// job ( )
	def str_search = "xxx-test"
	// job ( )
	def str_replace = "xxx-prod"
	def view = Hudson.instance.getView(str_view)
	//copy all projects of a view
	for(item in view.getItems())
	{
	  //   
      if (!item.getName(). contains(str_search)) {
        println(" $item.name ignore ")
        continue
      }
      //create the new project name
	  newName = item.getName().replace(str_search, str_replace)
	  // copy the job, disable and save it
	  def job
	  try {
	  	// , try-catch  job
	  	job = Hudson.instance.copy(item, newName)
	  } catch(IllegalArgumentException e) {
	     println(e.toString())
	     println("$newName job is exists")
	     continue
	  } catch(Exception e) {
	    println(e.toString())
	    continue
	  }
	  job.disabled = true
	  job.save() 
	  
	  // update the workspace to avoid having two projects point to the same location
	  // , 
	  //AbstractProject project = job
	  //def new_workspace = project.getCustomWorkspace().replace(str_search, str_replace)
	  //project.setCustomWorkspace(new_workspace)
	  //project.save()
	  //add job to view
	  Hudson.instance.getView(str_new_view).add(job)
	  println(" $item.name copied as $newName")
	}


これにより、生産の構築タスクの構成を変更するだけで済みます.