-1
folder('myfoler') {}

Above DSL Syntax from https://jenkinsci.github.io/job-dsl-plugin/#path/folder allowing me to create a folder myfoler. I need to create a directory.

Tried this:

folder('myfoler/mysubfoler') {}

This gives me error ERROR: Could not create item, unknown parent path in "myfoler/mysubfoler"

How do I create a full directory in single step?

anandhu
  • 686
  • 2
  • 13
  • 40
  • Please explain the reason for negative vote. Thee question seems very straightforward. I have explained with example and what I tried too – anandhu Jul 19 '23 at 04:55

1 Answers1

-1

you need to create parent folder and then nested

folder('myfoler') {}
folder('myfoler/mysubfoler') {}

you can use function to generate this

void createAllDirectories(String path) {
    String[] directories = path.split('/')
    String currentPath = ""

    directories.each { directory ->
        currentPath += directory + '/'
        folder(currentPath) {}
    }
}

// Example usage:
String path = "my/super/long/sweet/path"
createAllDirectories(path)
Ruslan
  • 444
  • 3
  • 8
  • yeah. I know that. But the ask was on how to create this entire directory on a single step. Imagine the directory path comes from a variable.. For example : 'ab/cd/ef/gh' . Is the only way is to separately create each path ? 'ab', 'ab/cd', 'ab/cd/ef', 'ab/cd/ef/gh' ? This sounds weird. There should be some easy way! – anandhu Jul 27 '23 at 05:28
  • 1
    https://github.com/jenkinsci/job-dsl-plugin/blob/c8a3dc07ef50c05645e8ad5cb41a237edb0e2662/job-dsl-plugin/src/main/java/javaposse/jobdsl/plugin/JenkinsJobManagement.java#L515-L536 see this its expected by plugin code it can not create item without parent item – Ruslan Jul 27 '23 at 20:56