Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-61956

ItemGroupMixin#createProject() does not call Jenkins#checkGoodName()

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • core
    • Jenkins 2.164.2
      Folders plugin 6.9
    • Jenkins 2.237

      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.

          [JENKINS-61956] ItemGroupMixin#createProject() does not call Jenkins#checkGoodName()

          Calvin Park created issue -
          Calvin Park made changes -
          Description Original: {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.
          New: {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.
          Daniel Beck made changes -
          Summary Original: createProject() and getItemsByFullName() handle nested folders inconsistently New: ItemGroupMixing#createProject() does not call Jenkins#checkGoodName
          Calvin Park made changes -
          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 ]
          Daniel Beck made changes -
          Summary Original: ItemGroupMixing#createProject() does not call Jenkins#checkGoodName New: ItemGroupMixin#createProject() does not call Jenkins#checkGoodName
          Daniel Beck made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Daniel Beck made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]
          Daniel Beck made changes -
          Status Original: In Review [ 10005 ] New: In Progress [ 3 ]
          Daniel Beck made changes -
          Status Original: In Progress [ 3 ] New: In Review [ 10005 ]
          Daniel Beck made changes -
          Remote Link New: This issue links to "PR 4684 (Web Link)" [ 24889 ]
          Calvin Park made changes -
          Summary Original: ItemGroupMixin#createProject() does not call Jenkins#checkGoodName New: ItemGroupMixin#createProject() does not call Jenkins#checkGoodName()

            Unassigned Unassigned
            calvinpark Calvin Park
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: