Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move jenkins job to sub folder?

Tags:

jenkins

I have 10 jenkins job in folder foo. I have created a new sub folder baar in folder foo. How to move the 10 jobs from folder foo to the subfolder baar?

like image 748
Max_Salah Avatar asked Sep 09 '16 07:09

Max_Salah


People also ask

How do I move Jenkins to another tab?

1) Click on the view in which you want to add the newly created Job as shown in pic. 2) Click on Edit View on left side and then select the appropriate job under Job Filter using the check box.

How do I create a folder in a folder in Jenkins?

Step #1: From within the desired folder, click “New Item” to create a new item (job/folder). In this case we're using the “Finance” folder we created in the previous task. Step #2: Enter a name in the textbox and select “Freestyle project” and click “OK” to create the job.

How do I copy a folder in Jenkins?

That being said, you can copy Jenkins folder structures (and their corresponding jobs) by simply doing a recursive copy/paste from the origin instance to the destination instance. Following the recursive copy, it may be necessary to restart the destination Jenkins instance in order for the folders and jobs to appear.


2 Answers

First, you need to install cloudbees folder plugin then you will see Move option in jobs

enter image description here

click on it,then option(drop down) will come where you want to move enter image description here

select and move

like image 92
Pratik Anand Avatar answered Sep 28 '22 03:09

Pratik Anand


As @Pratik Anand mentionned you will first need to install the CloudBees Folders Plugin.

However, if you want to move many projects at the same time, it is much faster to do it with the script console. This groovy script does the trick :

def FOLDER_NAME = '<An existing destination folder>' def JOB_REGEX = '<A regex to find your jobs>'  import jenkins.* import jenkins.model.* import hudson.* import hudson.model.*  jenkins = Jenkins.instance  def folder = jenkins.getItemByFullName(FOLDER_NAME) if (folder == null) {   println "ERROR: Folder '$FOLDER_NAME' not found"   return }  // Find jobs in main folder def found = jenkins.items.grep { it.name =~ "${JOB_REGEX}" } println "Searching main folder : $found"  // Find jobs in other subfolders jenkins.items.grep { it instanceof com.cloudbees.hudson.plugins.folder.Folder }.each { subfolder ->    if(!subfolder.getName().equals(FOLDER_NAME))   {     println "Searching folder '$subfolder.name'"     subfolder.getItems().grep { it.name =~ "${JOB_REGEX}" }.each { job ->       println "Found $job.name"       found.add(job);     }   } }  // Move them found.each { job ->   println "Moving '$job.name' to '$folder.name'"   Items.move(job, folder) } 

I used Daniel Serodio's reply in this thread and modified it to search subfolders also. Note that this is not fully recursive.

like image 21
JM Lord Avatar answered Sep 28 '22 03:09

JM Lord