This repository provides an automated Jenkins job provisioning system using the Jenkins Job DSL plugin and seed job pattern. It automatically creates and manages CI/CD pipelines for multiple services with standardized configurations and Bitbucket Cloud integration.
The system uses a seed job approach to automatically discover services and create their corresponding Jenkins multibranch pipeline jobs. Each service defines its configuration in YAML format, and the system generates the appropriate Jenkins jobs with:
- Bitbucket Cloud integration with proper webhook triggers
- Automated branch and PR discovery
- Standardized folder structure based on organizational tags
- Built-in validation and error handling
- One-time provisioning - jobs are created once and not overwritten
common-charts/
├── jenkins/seed/ # Seed job configuration
│ ├── SeedJenkinsfile # Main pipeline script
│ ├── seed.groovy # DSL script for seed job creation
│ ├── service_provisioner.groovy # Service provisioning logic
│ ├── yamlToMap.groovy # YAML parsing utility
│ ├── libs/ # Helper libraries
│ └── schema/ # JSON schema for validation
├── services/ # Service definitions
│ └── {service-name}/
│ ├── jenkins/
│ │ └── job.yaml # Service configuration (YAML only)
│ └── envs/ # Environment configs
├── ci/ # CI utilities
│ └── validate-job-yaml.sh # Configuration validation
└── util/ # Shared utilities
└── dsl-helpers.groovy # Reusable DSL functions
service_provisioner.groovy: Main provisioning logic using native Git DSL- Bitbucket Cloud Integration: Direct Git URL integration with webhook support
- YAML-only Configuration: Simplified service configuration without Groovy scripts
- Automated Discovery: Scans
services/directory for job configurations - Folder Structure:
Department/Team/Divisionbased on service tags
-
Create the seed job in Jenkins:
# Execute the seed DSL script in Jenkins # This creates the main seed job at Config/seed-job
-
Run the seed job to provision all service jobs automatically
-
Create service directory:
mkdir -p services/my-new-service/jenkins mkdir -p services/my-new-service/envs/{dev,uat,prod} -
Create job configuration (
services/my-new-service/jenkins/job.yaml):service: my-new-service project: common-charts # Bitbucket workspace name repo: tm-prod/my-service # Bitbucket repo: workspace/repository credentialsId: tmbuildjenkins-bitbucket jenkinsfile: Jenkinsfile # Path to Jenkinsfile in your repo tags: department: Backend # Used for folder structure team: TFBO # Department/Team/Division division: modern-microservices retention: daysToKeep: 14 numToKeep: 50
-
That's it! No Groovy scripts needed - the provisioner handles everything automatically.
-
Trigger the seed job - it will automatically discover and provision your new service
service: Service name (must match directory name)repo: Repository path in formatworkspace/repository(e.g.,tm-prod/my-service)credentialsId: Jenkins credentials ID for Bitbucket access
project: Bitbucket project key (informational)jenkinsfile: Path to Jenkinsfile (default: "Jenkinsfile")tags: Organizational structure for folder creationdepartment: Department name (e.g., "Backend", "Frontend")team: Team name (e.g., "TFBO", "Platform")division: Division name (e.g., "modern-microservices", "legacy")
retention: Build retention policiesdaysToKeep: Days to keep builds (default: 14)numToKeep: Number of builds to keep (default: 50)
- Branch Discovery: All branches automatically discovered
- PR Discovery: Origin and fork PRs with "both revisions" strategy
- Fork Trust: Set to "Nobody" for security
- Webhooks: Push and PR update triggers configured
- Periodic Scan: 30-minute backup scanning
See jenkins/seed/schema/job.schema.json for complete schema definition.
Validate all service configurations:
./ci/validate-job-yaml.shThis script checks:
- YAML syntax
- Required fields presence
- Service name consistency
- Basic Groovy syntax
- JSON schema compliance (if jq available)
- Jenkins with Job DSL plugin
- Bitbucket Server/Data Center integration
- Groovy runtime for local testing
- Python 3 (for YAML validation)
- jq (optional, for JSON schema validation)
- Validate configurations:
./ci/validate-job-yaml.sh - Test in development Jenkins instance
- Review generated jobs before promoting to production
The util/dsl-helpers.groovy provides reusable DSL functions:
ensureFolder(path): Creates nested folders with RBACbranchDiscovery(mode): Configures branch discoveryoriginPRDiscovery(enabled): Sets up origin PR discoveryforkPRDiscovery(enabled, trust): Configures fork PR handling
- Seed Job: Monitor
Config/seed-jobfor provisioning status - Service Jobs: Check individual service pipelines
- Validation: Review validation logs in seed job builds
- Scan Services Directory: Looks for all directories under
services/ - Validate Configuration: Checks for
jenkins/job.yamland validates structure - Parse Repository Info: Extracts Bitbucket workspace and repository names
- Create Folder Structure: Uses organizational tags to create Department/Team/Division folders
- Provision Job: Creates multibranch pipeline with Bitbucket Git integration
- Configure Webhooks: Sets up push and PR triggers automatically
- Jobs are created only if they don't already exist
- Existing jobs are not updated to prevent overwriting manual changes
- To update an existing job, delete it first and re-run the seed job
- Service not discovered: Check directory structure and YAML syntax
- Repository access failed: Verify Bitbucket credentials and repository permissions
- Webhook issues: Ensure Jenkins is accessible from Bitbucket Cloud
- Folder creation failed: Check Jenkins permissions and folder naming
- Check seed job console output for detailed error messages
- Validate YAML syntax using the validation script
- Verify repository URL format: Must be
workspace/repository - Test credentials by accessing repository manually with same credentials
- Follow the established service structure
- Validate configurations before committing
- Test changes in development environment
- Update documentation for new features
For questions and support:
- Check existing service configurations for examples
- Review Jenkins Job DSL documentation
- Contact the DevOps team for Jenkins-specific issues