0
0
Jenkinsdevops~5 mins

Organization folders in Jenkins - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing many Jenkins jobs can get confusing. Organization folders help group related jobs together automatically by scanning source code repositories. This keeps your Jenkins dashboard neat and organized.
When you have multiple projects stored in a single GitHub or Bitbucket organization and want Jenkins to create jobs for each automatically
When you want Jenkins to scan a folder of repositories and create pipelines for each without manual setup
When you want to keep your Jenkins dashboard clean by grouping jobs by team or project
When you want Jenkins to automatically detect new repositories and create jobs for them
When you want to apply common settings or credentials to all jobs inside a folder
Config File - organization-folder-config.xml
organization-folder-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<com.cloudbees.hudson.plugins.folder.Folder plugin="cloudbees-folder@6.15">
  <actions/>
  <description>Folder for all example organization repositories</description>
  <properties/>
  <folderViews class="com.cloudbees.hudson.plugins.folder.views.DefaultFolderViewHolder">
    <views>
      <hudson.model.AllView>
        <name>All</name>
        <filterExecutors>false</filterExecutors>
        <filterQueue>false</filterQueue>
        <properties class="hudson.model.View$PropertyList"/>
      </hudson.model.AllView>
    </views>
    <primaryView>All</primaryView>
  </folderViews>
  <healthMetrics/>
  <icon class="com.cloudbees.hudson.plugins.folder.icons.StockFolderIcon"/>
  <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder@6.15">
    <pruneDeadBranches>true</pruneDeadBranches>
    <daysToKeep>7</daysToKeep>
    <numToKeep>10</numToKeep>
  </orphanedItemStrategy>
  <triggers/>
  <com.cloudbees.hudson.plugins.folder.computed.FolderComputation plugin="cloudbees-folder@6.15">
    <scmSources>
      <jenkins.branch.OrganizationFolder$SCMSource>
        <id>example-org-github</id>
        <credentialsId>github-credentials</credentialsId>
        <repoOwner>example-org</repoOwner>
        <apiUri>https://api.github.com/</apiUri>
        <traits>
          <jenkins.plugins.git.traits.BranchDiscoveryTrait/>
          <jenkins.plugins.git.traits.TagDiscoveryTrait/>
          <jenkins.plugins.git.traits.OriginPullRequestDiscoveryTrait>
            <strategyId>1</strategyId>
          </jenkins.plugins.git.traits.OriginPullRequestDiscoveryTrait>
          <jenkins.plugins.git.traits.ForkPullRequestDiscoveryTrait>
            <strategyId>1</strategyId>
            <trust class="jenkins.plugins.git.traits.ForkPullRequestDiscoveryTrait$TrustEveryone"/>
          </jenkins.plugins.git.traits.ForkPullRequestDiscoveryTrait>
        </traits>
      </jenkins.branch.OrganizationFolder$SCMSource>
    </scmSources>
    <projectFactories>
      <jenkins.branch.WorkflowMultiBranchProjectFactory>
        <scriptPath>Jenkinsfile</scriptPath>
      </jenkins.branch.WorkflowMultiBranchProjectFactory>
    </projectFactories>
  </com.cloudbees.hudson.plugins.folder.computed.FolderComputation>
</com.cloudbees.hudson.plugins.folder.Folder>

This XML config defines an Organization Folder in Jenkins.

repoOwner is the GitHub organization to scan.

credentialsId is the Jenkins credential to access GitHub.

traits define what branches, tags, and pull requests to discover.

scriptPath tells Jenkins where to find the pipeline script in each repo.

This config automatically creates jobs for each repository in the organization.

Commands
This command creates an Organization Folder job in Jenkins using the XML config file. It tells Jenkins to scan the example-org GitHub organization.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080 create-job example-org-folder < organization-folder-config.xml
Expected OutputExpected
Created job example-org-folder
-s - Specifies the Jenkins server URL
This command triggers Jenkins to scan the organization folder and create jobs for each repository found.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080 build example-org-folder
Expected OutputExpected
Started build #1 for example-org-folder
-s - Specifies the Jenkins server URL
This command lists all jobs created inside the organization folder, showing the repositories Jenkins found and created jobs for.
Terminal
java -jar jenkins-cli.jar -s http://localhost:8080 list-jobs
Expected OutputExpected
repo1 repo2 repo3
-s - Specifies the Jenkins server URL
Key Concept

Organization folders automatically scan a source code organization and create Jenkins jobs for each repository to keep your CI/CD organized.

Common Mistakes
Not providing correct credentialsId in the config
Jenkins cannot access the GitHub API and fails to scan repositories
Create and use a valid Jenkins credential with access to the GitHub organization and reference its ID in the config
Using wrong repoOwner name or misspelling the organization
Jenkins will not find any repositories and create no jobs
Double-check the exact GitHub organization name and use it in the repoOwner field
Not triggering a build after creating the folder
Jenkins does not scan the organization automatically and no jobs are created
Run a build on the organization folder to start scanning and job creation
Summary
Create an organization folder in Jenkins using an XML config that defines the GitHub organization and credentials.
Trigger a build on the folder to scan repositories and create jobs automatically.
List jobs inside the folder to verify Jenkins found and created jobs for each repository.