Details
-
Bug
-
Status: Resolved (View Workflow)
-
Minor
-
Resolution: Fixed
-
Jenkins 2.164.2
Folders plugin 6.9
-
-
Jenkins 2.237
Description
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. At this point it's impossible to search for a folder with a slash in the name using getItemByFullName() function.
Attachments
Issue Links
- links to
Activity
Field | Original Value | New Value |
---|---|---|
Description |
{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. |
{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. |
Summary | createProject() and getItemsByFullName() handle nested folders inconsistently | ItemGroupMixing#createProject() does not call Jenkins#checkGoodName |
Comment |
[ I've tried to contribute to the {{cloudbees-folder-plugin}} git repo but {{mvn hpi:run}} fails. {code:java} cloudbees-folder-plugin master$ mvn hpi:run [INFO] Scanning for projects... [INFO] [INFO] --------------< org.jenkins-ci.plugins:cloudbees-folder >--------------- [INFO] Building Folders Plugin 6.13-SNAPSHOT [INFO] --------------------------------[ hpi ]--------------------------------- [INFO] [INFO] >>> maven-hpi-plugin:3.10:run (default-cli) > compile @ cloudbees-folder >>> [...] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ cloudbees-folder --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 45 source files to /Users/calvin/GitRepos/cloudbees-folder-plugin/target/classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] java.nio.file.NoSuchFileException: /Users/calvin/GitRepos/cloudbees-folder-plugin/target/classes/META-INF/annotations/hudson.Extension [INFO] 1 error [...]{code} The github page didn't enable {{Issues}} feature so I can't ask for help there [https://github.com/jenkinsci/cloudbees-folder-plugin] Any ideas on how to fix the compilation error? Thank you ] |
Summary | ItemGroupMixing#createProject() does not call Jenkins#checkGoodName | ItemGroupMixin#createProject() does not call Jenkins#checkGoodName |
Status | Open [ 1 ] | In Progress [ 3 ] |
Status | In Progress [ 3 ] | In Review [ 10005 ] |
Status | In Review [ 10005 ] | In Progress [ 3 ] |
Status | In Progress [ 3 ] | In Review [ 10005 ] |
Remote Link | This issue links to "PR 4684 (Web Link)" [ 24889 ] |
Summary | ItemGroupMixin#createProject() does not call Jenkins#checkGoodName | ItemGroupMixin#createProject() does not call Jenkins#checkGoodName() |
Released As | Jenkins 2.237 | |
Resolution | Fixed [ 1 ] | |
Status | In Review [ 10005 ] | Resolved [ 5 ] |
Labels | lts-candidate |
Labels | lts-candidate | 2.235.1-fixed |
Labels | 2.235.1-fixed | 2.235.2-fixed |
Labels | 2.235.2-fixed | 2.235.2-rejected |
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.