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

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

XMLWordPrintable

    • 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.

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

              Created:
              Updated:
              Resolved: