jenkinsjenkins-pipelinejenkins-job-dsl

Jenkins CASC Folder Syntax: How to organise jobs into folders?


I have the following Jenkins CASC syntax which works well, however I can find nothing in the Jenkins CASC docs on how to simply organise these jobs into folders:


unclassified:
  location:
    url: http://0.0.0.0:8888/
security:
  scriptApproval:
    approvedSignatures:
    - staticMethod org.codehaus.groovy.runtime.DefaultGroovyMethods putAt java.lang.Object java.lang.String java.lang.Object
jenkins:
  securityRealm:
    local:
      allowsSignup: false
      users:
        # create a user called admin
        - id: "admin"
          password: "admin"
  authorizationStrategy: loggedInUsersCanDoAnything

#numExecutors: 1

#Job Definitions using job-dsl plugin
jobs:
  - file: /usr/local/bootstrap-levels-nprd.groovy
  - file: /usr/local/bootstrap-levels-test-nprd.groovy
  - file: /usr/local/enterprise-caf-level0-certificate-rotation-nprd.groovy
  - file: /usr/local/enterprise-caf-level0-nprd.groovy
  - file: /usr/local/enterprise-destroy-level0-nprd.groovy
  - file: /usr/local/enterprise-caf-level1-nprd.groovy

The problem is two-fold:

With the advice provided by Dominik below I can create folders like this:

#Job Definitions using job-dsl plugin
jobs:
  - script: folder('Non-Production-CAF/bootstrap')

But there's nothing the documentation on how to make the pipelinescript .groovy definitions appear in the right folders.

I have tried this in the CASC configuration:

#Job Definitions using job-dsl plugin
jobs:
  - script: folder('Non-Production-CAF/bootstrap')
  - script: file('Non-Production-CAF/bootstrap/bootstrap-levels-nprd.groovy')
  - file: /var/jenkins_home/jobs/Non-Production-CAF/bootstrap/bootstrap-levels-nprd.groovy

Is there any Example configuration that would allow me to organise these jobs while still using the general style of configuration of the jobs ?


Solution

  • The Folders Plugin supplies this functionality, you can add folders similar to how you add jobs:

    jobs:
      - script: folder('A')
      - script: folder('A/B')
      - script: folder('A/B/C')
      - script: job('A/B/C/myjob')
    

    enter image description here