Renaming job in jenkins/hudson

前端 未结 8 2124
灰色年华
灰色年华 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:45

    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

    0 讨论(0)
  • 2020-12-30 20:45

    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.

    0 讨论(0)
  • 2020-12-30 20:49

    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.

    0 讨论(0)
  • 2020-12-30 20:49

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-30 21:02

    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')
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题