Folders Plugin Now with Support for Moving Items

Stephen Connolly's picture
CloudBees Folders plugin
The CloudBees Folders plugin provides a feature that is needed by so many people that once we had the basic Folders feature implemented we just had to release it… even though it was missing a key feature… namely the ability to move jobs and folders.
 
It’s not like we didn’t have a solution… more that our solution was… ahem… how can I put it… crap! The solution basically boiled down to the following:
  1. Stop Jenkins
  2. On the File system move the directories where you want them to go
  3. Start Jenkins again
Not so bad if you have a small Jenkins instance, but people who need folders typically have a rather large Jenkins instance.
 
Well, no more the stop/start solution, today we can announce the ability to move items between folders. 
 
Why did it take so long? Well, there were a number of technical problems that had to be addressed; for example, you should not move a folder while there are jobs in progress within the folder. Also, we need to take into account the fact that Jenkins is a multi-user system, so what happens when two users try to move folders at the same time? For example, I am trying to move job A into folder B and you are trying to move folder B into folder C.
 
So, our solution works as follows:
  • You submit a move request to Jenkins for the item you want to move.
  • The move request goes into the Jenkins queue.
  • When there are move requests on the Jenkins queue, a special temporary node is added to Jenkins to handle the move request. This node will only process move requests and can only handle one move request at a time, thereby removing race conditions.
  • When a move request is being processed:
    • Any of the jobs within the item are temporarily disabled to ensure that no new builds are started
    • Any in-progress builds block the move until they complete
    • The file system move is made (this will be retried a number of times to handle the case of Windows file locking preventing the move)
    • The Jenkins item’s parent is adjusted so that the configuration does not need to be reloaded
  • Once all move requests have been processed, the special temporary node is removed.

All this is available now if you upgrade to version 3.2 of the CloudBees Folders plugin. And if you haven’t got the CloudBees Folders plugin, it is available for free (registration required) if you install the CloudBees Free Enterprise Plugins.

—Stephen Connolly
CloudBees
www.cloudbees.com
 

 
Blog Categories: 

Comments

Great feature! But moving jobs in file system support was removed? It stopped to work here. This is useful when moving a lot of jobs...

@Andreyev: it should still work to move folders and jobs at the filesystem level, so long as you take care to do so while Jenkins is not running.

Worked! I forgot to create a config.xml file and put it in my-folder/jobs directory! I'm sorry about this, and thanks for your attention! PS: CloudBees supported plugins will not receive a page on wiki/confluence?

http://wiki.cloudbees.com/bin/view/Jenkins+Enterprise/CloudBees+Free+and+Open+Source+Jenkins+Plugins#HCloudBeesFolderPlugin

Will there be support to create a folder and move a job via API?

Creating a folder works like creating any other job: you just POST the desired config.xml to newItem. Jobs can be moved using /move?destination=/other/folder.

POSTing to /job/original/job/folder/job/jobname/move/move?destination=/other/folder that is.

Add new comment