Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming job in jenkins/hudson

Tags:

jenkins

hudson

People also ask

How do I rename a Jenkins job?

In New Jenkins, Click Rename link present in the left navigation pane, Update the job name and click save. Show activity on this post. Simply change the name in the Pipeline/Project name and hit save.

How many jobs we can create in Jenkins?

2 Answers. Show activity on this post. Jenkins can run as many jobs as you have available "executors". You can change the number of executors at will in the configuration.

How do I write a resume for Jenkins?

Probable Solution --> You could use Build Pipeline plugin, https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin , and if the job fails at say second job, then all you have to do is restart the second job from the pipeline and it would continue from there.


You can rename selected job through jenkins UI by following these steps:

job>configure>Advanced Project Options>Display Name

Other way is to rename the directory on the Jenkins/hudson server and then restart the Jenkins.


For Quick understanding I used some screenshots:

I used Jenkins version: 2.148

Step 1:

On home screen / Job list just click on job option.

enter image description here

OR

Just open Job details you will see left side option for rename.

enter image description here

Step 2:

Enter new name and just click on Rename button

enter image description here


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.


The normal way to rename a job:

Go to the Configure screen and edit the Project name field right on top. Then click on Save and confirm by clicking on Yes. (do not click on the Apply button next to Save, that will give you an error message: JENKINS-17474)

Changing the Display Name will not rename the job, it only changes how it will be displayed. It will still be found under it's original name via the search box for example and that also will show up in the url.

Renaming directories on the filesystem level should really not be necessary.


  1. Create a new job with new name, there will be an option of copy from an existing job.
  2. copy from the job you want to rename.
  3. Delete the original job.

Now you have an identical job with a different name.


Depending on the requirement I usually choose between:

Job > Configure - modify Project Name property - Advanced Project Options, hit Advanced..., set value for Display Name

Then Save the job. No need to rename on file system level.


I can't make Marc's script work, so write one based on Disable all jobs script as shown below. This is to rename any project with "Findur.OpenComponent" to "Findur.OpenComponents".

import hudson.model.*

renameChildren(Hudson.instance.items)

def renameChildren(items) {
  for (item in items) {
    if (item.class.canonicalName != 'com.cloudbees.hudson.plugins.folder.Folder') {     
      if (( m = item.name =~ /^(Findur.OpenComponent)(\..*)$/)){
        println(item.name)
        println m.group(1) + " " + m.group(2)
        newname = m[0][1] + 's' + m.group(2)
        item.renameTo(newname)
      }

    } else {
        renameChildren(((com.cloudbees.hudson.plugins.folder.Folder) item).getItems())
    }
  }
}