Job DSL

Generating Jobs with the Job DSL Plugin

JCasC 2,791 leaves jobs to the Job DSL 1,924 plugin (3732.v9a_c49a_61a_313): Groovy scripts that describe jobs. JCasC's jobs: key runs them at startup and reload; the older way is a seed job with a Process Job DSLs step. This script creates a multibranch job per repository, with Jenkinsfiles in Source Control's settings:

ci/jenkins/jobs.groovyGroovy
// Job DSL: one multibranch job per BookNest repository
['booknest-jenkins', 'booknest-jenkins-lib'].each { repo ->
  multibranchPipelineJob(repo) {
    displayName("BookNest (${repo})")
    branchSources {
      branchSource {
        source {
          github {
            id(repo)
            repoOwner('binarybehemoth')
            repository(repo)
            repositoryUrl("https://github.com/binarybehemoth/${repo}")
            configuredByUrl(false)
            credentialsId('github-booknest')
            traits {
              gitHubBranchDiscovery { strategyId(1) }
              gitHubPullRequestDiscovery { strategyId(1) }
            }
          }
        }
      }
    }
    orphanedItemStrategy {
      discardOldItems { daysToKeep(7); numToKeep(5) }
    }
    triggers { periodicFolderTrigger { interval('4h') } }
  }
}

A list and a loop replace copy and paste. github { ... } comes from Job DSL's dynamic DSL, generated from the installed plugins' @Symbols; the Job DSL API Reference page lists them. Both jobs indexed at once:

What branch indexing found in the two generated jobsGroovy
C=http://localhost:32081
for job in booknest-jenkins booknest-jenkins-lib; do
  curl -s -u "admin:$P" $C/job/$job/indexing/consoleText \
    | grep -E "Checking branch|Jenkinsfile|criteria"
done
Output
  Checking branches...
    Checking branch main
      ‘Jenkinsfile’ found
    Met criteria
  Checking branches...
    Checking branch main
      ‘Jenkinsfile’ not found
    Does not meet criteria

The library has no Jenkinsfile yet, so its job stays empty. Job DSL in a seed job runs in the Groovy sandbox by default; from JCasC's file it is trusted like the YAML.