Reputation:
I have tried to rename a hudson/jenkins job. However it failed to rename.
Is there any way so I can rename the job?
Upvotes: 38
Views: 48052
Reputation: 9383
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.
OR
Just open Job details you will see left side option for rename.
Step 2:
Enter new name and just click on Rename button
Upvotes: 24
Reputation: 61
copy from
an existing job.copy from
the job you want to rename.Now you have an identical job with a different name.
Upvotes: 6
Reputation: 54611
Use the function Job.previousNames()
to rename multiple jobs using Groovy script within a [job generator](Job Generator Plugin) (factory).
The following example renames the jobs ci.*_2
to ci.*
(it removes the trailing _2
).
[
[env: '01', hostname: 'host01.intranet'],
[env: '02', hostname: 'host02.intranet'],
[env: '03', hostname: 'host03.intranet'],
[env: '04', hostname: 'host04.intranet'],
[env: '05', hostname: 'host05.intranet'],
[env: '06', hostname: 'host06.intranet'],
[env: '07', hostname: 'host07.intranet'],
[env: '08', hostname: 'host08.intranet'],
[env: '09', hostname: 'host09.intranet'],
[env: '10', hostname: 'host10.intranet'],
[env: '11', hostname: 'host11.intranet'],
[env: '12', hostname: 'host12.intranet'],
[env: '13', hostname: 'host13.intranet'],
[env: '14', hostname: 'host14.intranet'],
[env: '15', hostname: 'host15.intranet'],
[env: '16', hostname: 'host16.intranet'],
[env: '17', hostname: 'host17.intranet'],
[env: '18', hostname: 'host18.intranet'],
[env: '19', hostname: 'host19.intranet'],
[env: '20', hostname: 'host20.intranet'],
].each { Map config ->
job("ci.${config.env}") {
previousNames("ci.${config.env}_2")
description("Continuous Integration on host ${config.env}")
logRotator {
numToKeep(5)
daysToKeep(45)
}
label('build')
wrappers {
colorizeOutput('gnome-terminal')
}
}
}
Upvotes: 0
Reputation: 3938
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
.
Upvotes: 71
Reputation: 2375
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())
}
}
}
Upvotes: 2
Reputation: 5082
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.
Upvotes: 18
Reputation: 2958
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.
Upvotes: 11
Reputation: 3119
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.
Upvotes: 1