jenkinsci / configuration-as-code-plugin

Jenkins Configuration as Code Plugin
https://plugins.jenkins.io/configuration-as-code
MIT License
2.7k stars 720 forks source link

Jenkins CASC Folder Syntax: How to organise pipelinescript-defined job files into folders? #2529

Open archmangler opened 4 months ago

archmangler commented 4 months ago

Describe your use-case which is not covered by existing documentation.

I have the following Jenkins CASC syntax which works well to create folders in the Jenkins U.I.

.
.
.
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:
  - script: folder('Non-Production-CAF/bootstrap')
  - file: /usr/local/bootstrap-levels-test-nprd.groovy

However I can find nothing in the Jenkins CASC docs on how to simply organise these jobs (defined by groovy declarative pipelinescript) into folders. I have tried this:


#Job Definitions using job-dsl plugin
jobs:
  - script: folder('Production-CAF')
.
.
.
  - 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

But the pipelinescript groovy "bootstrap-levels-nprd.groovy" is not interpreted and instantiated as a job in the folder "Non-Production-CAF/bootstrap/".

Does the folder plugin CASC support this ? If so please can we have a documentation example for exactly this case?

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

  1. https://plugins.jenkins.io/cloudbees-folder/
  2. https://github.com/jenkinsci/job-dsl-plugin/wiki/Job-DSL-Commands#folder