Renaming job in jenkins/hudson

前端 未结 8 2175
灰色年华
灰色年华 2020-12-30 20:20

I have tried to rename a hudson/jenkins job. However it failed to rename.

Is there any way so I can rename the job?

8条回答
  •  我在风中等你
    2020-12-30 20:56

    Just for the sake of completeness, want to mention the update of Hudson job name using Groovy script console:

    // Groovy script to rename job in Hudson
    import hudson.model.*;
    
    def JOB_PATTERN = ~/^MY_JOB.*$/; //find all jobs starting with "MY_JOB".
    def NEW_PART = "_NEW"
    
    (Hudson.instance.items.findAll { job -> job.name =~ JOB_PATTERN }).each { job_to_update -> 
        println ("Updating job " + job_to_update.name);
        def new_job_name = job_to_update.name + NEW_PART; //Append new part to the job name
        println ("New name: " + new_job_name);
        job_to_update.renameTo(new_job_name);
        println ("Updated name: " + job_to_update.name);
        println("="*80);
    }
    

    Rather helpful if you need to update several dozens of jobs at the same time.

    Note: The following code will not work:

    job_to_update.name = new_job_name;
    job_to_update.save();
    

    Setting the name of the job to new and saving configuration will not rename current job, but create a copy of the job configuration with a new name. Also, in this case, there might be broken references, so Hudson will need to have configuration reloaded.

提交回复
热议问题