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

Create parent directories first when parsing new jobDsl scripts

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • job-dsl-plugin
    • None
    • Jenkins 2.412, jobDsl plugin 1.87

      Description

      I am playing with the Jenkins CasC plugin to make our systems more robust and easier to rollback in the event of failure/disaster. 

      I have setup the jobDsl seed job as described in the JCasC docs and it almost works fine. We have multiple applications so our jobDsl repo looks something like this:

      jobDslRepo/
      ├── APP1/
      │   ├── BUILD/
      │   │   ├── script1.groovy
      │   │   ├── script2.groovy
      │   │   └── directory.groovy
      │   ├── DEPLOY/
      │   │   ├── script1.groovy
      │   │   ├── script2.groovy
      │   │   └── directory.groovy
      │   └── directory.groovy
      ├── APP2/
      │   ├── BUILD/
      │   │   ├── script1.groovy
      │   │   ├── script2.groovy
      │   │   └── directory.groovy
      │   ├── DEPLOY/
      │   │   ├── script1.groovy
      │   │   ├── script2.groovy
      │   │   └── directory.groovy
      │   └── directory.groovy
      └── APP3/
          ├── BUILD/
          │   ├── script1.groovy
          │   ├── script2.groovy
          │   └── directory.groovy
          ├── DEPLOY/
          │   ├── script1.groovy
          │   ├── script2.groovy
          │   └── directory.groovy
          └── directory.groovy 

      The directory.groovy file define a folder like this:

      // This is an example of APP1/directory.groovy
      String F_ROOT = "APP1"
      
      folder(F_ROOT) {
          (other configuration here)
      }

      Or, for child folders, something like this:

      // This is an example of APP1/BUILD/directory.groovy
      String F_ROOT = "APP1/BUILD"
      
      folder(F_ROOT) {
          (other configuration here)
      }
      // This is dependent on the APP1 folder already existing.

      Now the main issue is that it seems like the plugin is reading all these files in order, so the first file to be read is APP1/BUILD/script1.groovy. This file has a dependency on the APP1/BUILD directory being created already, so the seed job just fails immediately.

      In order to get this to work, I need to change my targets() definition to search for

      */directory.groovy

      to obtain all the top level directories, then I can change it back to what it was originally

      (*/*.groovy, */*/*.groovy)

      to read my remaining files.

      Proposal

      I propose that the jobDsl plugin should read files descending the hierarchy and give precedence to any files that define a new folder() so that the seed job can create a very large amount of folders and jobs all at once, without failing due to a job definitions dependency on a parent or grandparent folder.

       

       

            jamietanna Jamie Tanna
            wmoorby Will Moorby
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: