Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-36282] Add support for exporting jobs in folders recursively #1

Closed
wants to merge 8 commits into from

Conversation

dwnusbaum
Copy link
Member

JENKINS-36282

I added the ability to specify a query parameter to list all jobs recursively in cc.xml. I made it optional in case someone relies on the current behavior, but if that isn't an issue we could just make the recursive behavior a non-optional default.

The name of jobs in folders are prefixed by the folder name, i.e. <Project ... name="Folder1/Project1">, so I believe this also fixes JENKINS-34641.

@reviewbybees


private Map<String, Collection<TopLevelItem>> getItemsRecursive(String namePrefix, Collection<TopLevelItem> items) {
Map<String, Collection<TopLevelItem>> result = new HashMap<>();
List<TopLevelItem> currentLevelItems = new ArrayList<>();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on the number of folders and projects on the Jenkins instance, and how sparse the folders are, these ArrayList and HashMap objects might have a lot of unused space. Does anyone think I should make them a smaller size to start, or use a LinkedList instead or anything?

@ghost
Copy link

ghost commented Sep 21, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@dwnusbaum
Copy link
Member Author

dwnusbaum commented Sep 22, 2017

This wiki page would need to be updated as well.

@oleg-nenashev
Copy link
Member

It's probably a correct fix, but it would be great to know @daniel-beck's plans about releasing the plugin.

So far it is not released, and the issue probably needs to be fixed in the core

@dwnusbaum
Copy link
Member Author

Yes it requires that JENKINS-40750 be completed. I'm not sure if the current PR to remove cc.xml from core is waiting for a new LTS release or anything.

@oleg-nenashev
Copy link
Member

It just hangs since @daniel-beck has lots of other things to do, I'd guess.

Maybe a correct approach is to fix the issue in the core now and then to integrate this PR here so that the fix will get applied after detaching.

If you consider it as an issue requiring backporting, then the fix needs to submitted against the core for sure.

@daniel-beck
Copy link
Member

I expect this will kick me into finally acting on this in the next few days. Shouldn't be too much work.

@daniel-beck daniel-beck self-assigned this Sep 22, 2017
@dwnusbaum
Copy link
Member Author

@daniel-beck I am happy to help write any wiki pages or documentation that is needed to release this plugin.

* as well. The map is keyed by the folder the item is in, with top-level
* items having an empty key.
*/
public Map<String, Collection<TopLevelItem>> getItems() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is considered as a backportable bugfix, new public methods should be marked as @Restricted(NoExternalUse.class)

for (TopLevelItem i : items) {
if (i instanceof ItemGroup) {
ItemGroup g = (ItemGroup) i;
result.putAll(getItemsRecursive(namePrefix + g.getDisplayName() + "/", g.getItems()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about Display Name here. It causes some concerns since you duplicate the core's logic here. I would rather suggest to use Item#getFullDisplayName though it decreases the performance of the call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about Item#getFullDisplayName, so I will update it to use that.

@@ -28,19 +28,21 @@ THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<st:contentType value="text/xml;charset=UTF-8" />
<st:contentType value="application/xml;charset=UTF-8" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to RFC referenced in https://stackoverflow.com/questions/4832357/whats-the-difference-between-text-xml-vs-application-xml-for-webservice-respons . I would argue that "text/xml" was correct since the output is really "readable by casual users". It is also not related to the bug from what I see

Copy link
Member Author

@dwnusbaum dwnusbaum Sep 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I changed it to make the testing logic simpler as JenkinsRule#createWebClient#goToXml requires application/xml (Maybe that method should also accept text/xml?). I will change it back and update the tests.

for (TopLevelItem i : items) {
if (i instanceof ItemGroup) {
ItemGroup g = (ItemGroup) i;
result.addAll(getItemsRecursive(g.getItems()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

passing target array as an argument would make the method much more efficient from the memory allocation perspective. Now you allocate a new array list for every Folder/ItemGroup just to move them to another array on the upper level. And so on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a very good point, I'll fix it. Thanks!

Copy link
Member

@oleg-nenashev oleg-nenashev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐝

@jglick
Copy link
Member

jglick commented Oct 4, 2017

@reviewbybees done

@dwnusbaum
Copy link
Member Author

dwnusbaum commented Jan 12, 2018

This went into core with some changes as jenkinsci/jenkins#3060 and jenkinsci/jenkins#3081. This PR would need to be modified to match those fixes instead.

@dwnusbaum dwnusbaum closed this Jan 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants