[JIRA] (JENKINS-61956) createProject() and getItemsByFullName() handle nested folders inconsistently

15 views
Skip to first unread message

calvinspark@gmail.com (JIRA)

unread,
Apr 17, 2020, 6:12:03 PM4/17/20
to jenkinsc...@googlegroups.com
Calvin Park created an issue
 
Jenkins / Bug JENKINS-61956
createProject() and getItemsByFullName() handle nested folders inconsistently
Issue Type: Bug Bug
Assignee: Unassigned
Components: core
Created: 2020-04-17 22:11
Environment: Jenkins 2.164.2
Folders plugin 6.9
Priority: Minor Minor
Reporter: Calvin Park
String nested = "one/two"

// Creates a single folder named "one/two" with / embedded in the name
createProject(Folder.class, nested)

// Looks for a subfolder named "two" inside a folder named "one"
getItemByFullName(nested)

As a result, this code fails

import com.cloudbees.hudson.plugins.folder.Folder

String folder = "nested/folders"

create_folder_if_missing(folder)
create_folder_if_missing(folder)

void create_folder_if_missing(String folder) {
  def item = Jenkins.instance.getItemByFullName(folder)

  if (item == null) {
    println(folder + " not found. Creating.")
    Jenkins.instance.createProject(Folder.class, folder)
    println("Created " + folder)
  }
  else {
    println(folder + " found. Skipping.")
  }
}

with the result

nested/folders not found. Creating.
Created nested/folders
nested/folders not found. Creating.
java.lang.IllegalArgumentException: nested/folders already exists
	at hudson.model.Items.verifyItemDoesNotAlreadyExist(Items.java:641)

I think createProject(Folder.class, nested) should change its behavior to look for slashes and create subfolders, rather than allowing a slash in a folder name.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo

calvinspark@gmail.com (JIRA)

unread,
Apr 17, 2020, 6:15:03 PM4/17/20
to jenkinsc...@googlegroups.com
Calvin Park updated an issue
Change By: Calvin Park
{code:java}

String nested = "one/two"

// Creates a single folder named "one/two" with / embedded in the name
createProject(Folder.class, nested)

// Looks for a subfolder named "two" inside a folder named "one"
getItemByFullName(nested)
{code}

As a result, this code fails
{code:java}

import com.cloudbees.hudson.plugins.folder.Folder

String folder = "nested/folders"

create_folder_if_missing(folder)
create_folder_if_missing(folder)

void create_folder_if_missing(String folder) {
  def item = Jenkins.instance.getItemByFullName(folder)

  if (item == null) {
    println(folder + " not found. Creating.")
    Jenkins.instance.createProject(Folder.class, folder)
    println("Created " + folder)
  }
  else {
    println(folder + " found. Skipping.")
  }
}
{code}
with the result
{code:java}

nested/folders not found. Creating.
Created nested/folders
nested/folders not found. Creating.
java.lang.IllegalArgumentException: nested/folders already exists
at hudson.model.Items.verifyItemDoesNotAlreadyExist(Items.java:641)
{code}

I think {{createProject(Folder.class, nested)}} should change its behavior to look for slashes and create subfolders, rather than allowing a slash in a folder name.
At this point it's impossible to search for a folder with a slash in the name using {{getItemByFullName()}} function.

dbeck@cloudbees.com (JIRA)

unread,
Apr 17, 2020, 6:49:02 PM4/17/20
to jenkinsc...@googlegroups.com
Daniel Beck commented on Bug JENKINS-61956
 
Re: createProject() and getItemsByFullName() handle nested folders inconsistently

Looks like createProject is missing a call to Jenkins#checkGoodName but that's about it.

dbeck@cloudbees.com (JIRA)

unread,
Apr 17, 2020, 6:50:03 PM4/17/20
to jenkinsc...@googlegroups.com
Daniel Beck edited a comment on Bug JENKINS-61956
Looks like {{createProject}} is missing a call to {{Jenkins#checkGoodName}} but that's about it.


While it would be more convenient to have a "createByFullName" that splits at the last {{/}}, finds the folder for the first part and inserts the item named the second part, that's a quick utility method.

calvinspark@gmail.com (JIRA)

unread,
Apr 17, 2020, 6:57:02 PM4/17/20
to jenkinsc...@googlegroups.com

Is this a regression? Our folder creation script had been working for a few years and now it fails with this problem. I'm not sure what changed since we rarely upgrade master

dbeck@cloudbees.com (JIRA)

unread,
Apr 17, 2020, 7:36:02 PM4/17/20
to jenkinsc...@googlegroups.com

Is this a regression?

Tried it back to 1.620, a 5 years old release, doesn't work.

println Jenkins.instance.getItemByFullName("foo/bar")
Jenkins.instance.createProject(com.cloudbees.hudson.plugins.folder.Folder.class, "foo/bar")
println Jenkins.instance.getItemByFullName("foo/bar")

Output is

null
null

So no regression here for any sensible definition of the term. Nobody cares what happened >5 years ago.

calvinspark@gmail.com (JIRA)

unread,
Apr 17, 2020, 7:39:02 PM4/17/20
to jenkinsc...@googlegroups.com

Thank you for checking. Thoughts on making createProject handle subfolders?

dbeck@cloudbees.com (JIRA)

unread,
Apr 18, 2020, 3:39:03 PM4/18/20
to jenkinsc...@googlegroups.com

It's like 5 lines of code to write a utility function. Don't be so lazy.

Reply all
Reply to author
Forward
0 new messages