JobGenie - Complete Guide

Your friendly Jenkins job generator - Comprehensive guide to JobGenie job generation engine

Updated Jan 15, 2024
10 min read
Intermediate
tools

JobGenie - Complete Guide

Your friendly Jenkins job generator - Comprehensive guide to JobGenie job generation engine

πŸ“‹ Table of Contents

🎯 Overview

JobGenie is a powerful Jenkins job generation engine that transforms simple Groovy map definitions into fully functional Jenkins pipelines. It eliminates the need for manual job creation and provides a consistent, scalable approach to CI/CD pipeline management.

Key Benefits

  • βœ… Zero Manual Configuration: Define jobs in code, not UI
  • βœ… Consistency: Same structure across all jobs
  • βœ… Scalability: Generate hundreds of jobs from simple configs
  • βœ… Maintainability: Version-controlled job definitions
  • βœ… Flexibility: Support for various job types and patterns

🧠 Core Concepts

1. JobGenie Map Structure

JobGenie uses nested Groovy maps to define jobs:

def jobGenie = [
    "techteam-name": [
        [ /* Job 1 Configuration */ ],
        [ /* Job 2 Configuration */ ],
        [ /* Job 3 Configuration */ ]
    ]
]

2. Configuration Hierarchy

Configurations are merged in this order (later overrides earlier):

  1. defaultConfigs: Global defaults for all jobs
  2. projectConfigs: Project-specific overrides
  3. jobGenie entries: Individual job configurations

3. Variable Resolution

Variables are resolved using this precedence:

  • Job-specific variables (highest priority)
  • Project-specific variables
  • Default variables (lowest priority)

πŸ“ Configuration Structure

Basic Structure

// 1. Default configurations (applied to all jobs)
def defaultConfigs = [
    EKS_CLUSTER_NAME: "my-cluster",
    CICD_TEMPLATE_BASE: 'templates/cicd',
    IMAGE_ECR: "1234567890.dkr.ecr.ap-south-1.amazonaws.com",
    // ... more defaults
]

// 2. Project-specific configurations
def projectConfigs = [
    "mcloud": [
        GROUP: "v3",
        ENV: "stage"
    ]
]

// 3. JobGenie definitions
def jobGenie = [
    "mcloud": [
        [
            APP_REPO: 'my-application',
            APP_BRANCH: 'master',
            appNames: ['my-service']
        ]
    ]
]

Required Variables

For Standard Application Jobs

[
    APP_REPO: 'repository-name',      // Git repository name
    APP_BRANCH: 'branch-name',       // Git branch
    appNames: ['service-name']       // List of service names
]

For Custom Jobs

[
    SERVICE: 'service-name',          // Service identifier
    CICD_TEMPLATE_NAME: 'template',  // Pipeline template
    JOB_PARAMS: [ /* parameters */ ] // Job parameters
]

Optional Variables

Docker Build Configuration

DOCKER_BUILD_DIR: 'path/to/docker',     // Docker build directory
DOCKERFILE_PATH: 'Dockerfile',          // Dockerfile path
DOCKER_BUILD_ARGS: 'ENV,TECHTEAM',      // Build arguments
DOCKER_IMAGE_ARCH: 'linux/arm64',       // Image architecture

Git Configuration

SSH_KEYS: 'default:/path/to/key',       // SSH key path
CONFIG_REPO: 'config-repo',             // Config repository
CONFIG_BRANCH: 'master',                // Config branch

Kubernetes/ArgoCD Configuration

ARGOCD_ENDPOINT: 'argocd.example.com',  // ArgoCD endpoint
ARGOCD_PROJECT: 'project-name',         // ArgoCD project
HELM_CHART: 'chart-name',               // Helm chart name
HELM_CHART_VERSION: '1.0.0',           // Chart version

Build Tools

MAVEN_VERSION: 'maven3.9.7',            // Maven version
JDK_VERSION: 'jdk21',                  // JDK version
NODE_VERSION: 'node18',                // Node.js version

🎨 Job Types

1. Standard Application Jobs

Purpose: Build and deploy standard Kubernetes applications

Configuration:

[
    APP_REPO: 'my-application',
    APP_BRANCH: 'develop',
    appNames: ['api-service', 'worker-service']
]

Generated Jobs:

  • {ENV}-{service-name}-pipeline: Main build/deploy pipeline

Parameters:

  • APP_BRANCH: Application git branch
  • OPERATION: build promote abort
  • EXTENT: none full
  • STEPS: Number of canary steps

2. Build + Deploy Jobs

Purpose: Separate build and deploy jobs for complex workflows

Configuration:

[
    APP_REPO: 'my-application',
    APP_BRANCH: 'develop',
    appNames: ['api-service'],
    BUILD: [
        NAME: 'api-service'
    ]
]

Generated Jobs:

  • {ENV}-{BUILD.NAME}-build: Build-only job
  • {ENV}-{service-name}-deploy: Deploy job with image selection

Deploy Job Parameters:

  • ImageTag: Dynamic ECR image tag selection
  • OPERATION: prepare-changes promote abort

3. Custom Jobs

Purpose: Jobs with custom templates and parameters

Configuration:

[
    SERVICE: 'custom-service',
    CICD_TEMPLATE_NAME: 'custom-template',
    JOB_PARAMS: [
        [ name: 'TAG', string: 'latest', description: 'Deployment tag' ],
        [ name: 'ENV', choices: ['dev', 'prod'], description: 'Environment' ]
    ]
]

Generated Jobs:

  • {SERVICE}-pipeline: Custom pipeline job

4. Frontend/Non-K8s Jobs

Purpose: Jobs for non-Kubernetes deployments

Configuration:

[
    SERVICE: 'frontend-app',
    CICD_TEMPLATE_NAME: 'frontend-template',
    JOB_PARAMS: [ /* custom parameters */ ]
]

πŸš€ Advanced Features

1. Multi-Application Support

Define multiple applications in a single entry:

[
    APP_REPO: 'monorepo',
    APP_BRANCH: 'main',
    appNames: ['service-a', 'service-b', 'service-c']
]

Result: Generates separate jobs for each service

2. Environment-Specific Configuration

Override defaults per environment:

def projectConfigs = [
    "mcloud": [
        GROUP: "v3",
        ENV: "stage"
    ],
    "ncloud": [
        GROUP: "v2",
        ENV: "prod"
    ]
]

3. Dynamic Parameters

Use Groovy scripts for dynamic parameter values:

[
    name: 'ImageTag',
    choiceType: 'SINGLE_SELECT',
    arChoiceGroovy: """
        def command = "aws ecr describe-images --repository-name ${ECR_REPO} --query 'sort_by(imageDetails[?imageTags != null], &imagePushedAt)[-5:].imageTags[]' --output text"
        def aws_command_output = ["/bin/sh", "-c", "\${command}"].execute()
        def files = aws_command_output.text.tokenize().reverse()
        return files
    """
]

4. Feature Branch Support

Enable beta/testing features:

[
    APP_REPO: 'my-app',
    APP_BRANCH: 'feature/new-deployment',
    appNames: ['my-service'],
    BETA: true  // Uses template-based Jenkinsfile
]

5. Custom Jenkinsfile Path

Specify custom Jenkinsfile location:

[
    SERVICE: 'custom-service',
    DEFAULT_JENKINSFILE: 'custom/path/Jenkinsfile',
    JOB_PARAMS: [ /* parameters */ ]
]

πŸ“š Examples

Example 1: Simple Application

def jobGenie = [
    "mcloud": [
        [
            APP_REPO: 'user-service',
            APP_BRANCH: 'develop',
            appNames: ['user-api']
        ]
    ]
]

Generated:

  • Job: amazon/mcloud/nonprod/deploy/v2/stage/user-api/stage-user-api-pipeline
  • Parameters: APP_BRANCH, OPERATION, EXTENT, STEPS

Example 2: Multi-Service Application

def jobGenie = [
    "mcloud": [
        [
            APP_REPO: 'microservices-platform',
            APP_BRANCH: 'main',
            appNames: ['api-gateway', 'auth-service', 'payment-service'],
            DOCKER_BUILD_ARGS: 'ENV,TECHTEAM'
        ]
    ]
]

Generated: Three separate pipeline jobs, one per service

Example 3: Build + Deploy Pattern

def jobGenie = [
    "mcloud": [
        [
            APP_REPO: 'complex-app',
            APP_BRANCH: 'release/v2.0',
            appNames: ['api', 'worker', 'scheduler'],
            BUILD: [
                NAME: 'complex-app'
            ],
            DOCKER_BUILD_ARGS: 'ENV,VERSION'
        ]
    ]
]

Generated:

  • Build job: stage-complex-app-build
  • Deploy jobs: stage-api-deploy, stage-worker-deploy, stage-scheduler-deploy

Example 4: Custom Template Job

def jobGenie = [
    "mcloud": [
        [
            SERVICE: 'data-pipeline',
            CICD_TEMPLATE_NAME: 'data-processing',
            DEFAULT_JENKINSFILE: 'templates/data-pipeline/Jenkinsfile',
            JOB_PARAMS: [
                [ name: 'DATA_SOURCE', string: 's3://bucket/data', description: 'Data source path' ],
                [ name: 'PROCESSING_MODE', choices: ['batch', 'stream'], description: 'Processing mode' ],
                [ name: 'DRY_RUN', bool: false, description: 'Dry run mode' ]
            ]
        ]
    ]
]

Example 5: Advanced Configuration

def jobGenie = [
    "mcloud": [
        [
            APP_REPO: 'enterprise-app',
            APP_BRANCH: 'production',
            appNames: ['main-service'],
            // Docker configuration
            DOCKERFILE_PATH: 'services/main/Dockerfile',
            DOCKER_BUILD_ARGS: 'ENV,REGION,VERSION',
            DOCKER_IMAGE_ARCH: 'linux/arm64',
            // Git configuration
            SSH_KEYS: 'default:/var/lib/jenkins/.ssh/id_rsa',
            // Build tools
            MAVEN_VERSION: 'maven3.9.7',
            JDK_VERSION: 'jdk21',
            // ArgoCD configuration
            ARGOCD_ENDPOINT: 'argocd.prod.example.com',
            ARGOCD_PROJECT: 'production-apps',
            HELM_CHART: 'enterprise-chart',
            HELM_CHART_VERSION: '2.1.0',
            // Feature flags
            CREATE_KIBANA_DATAVIEW: true,
            CREATE_AWS_SECRET: true
        ]
    ]
]

βœ… Best Practices

1. Configuration Organization

βœ… DO:

// Group related jobs together
def jobGenie = [
    "mcloud": [
        // All mcloud jobs here
    ],
    "ncloud": [
        // All ncloud jobs here
    ]
]

❌ DON’T:

// Don't mix teams
def jobGenie = [
    "mcloud": [ /* mcloud job */ ],
    "mcloud": [ /* another mcloud job */ ]  // Duplicate key
]

2. Variable Naming

βœ… DO:

  • Use descriptive names
  • Follow naming conventions
  • Document custom variables

❌ DON’T:

  • Use ambiguous names
  • Mix naming styles
  • Create unnecessary variables

3. Default Configuration

βœ… DO:

// Set sensible defaults
def defaultConfigs = [
    EKS_CLUSTER_NAME: "${PROJECT_NAME}-eks-${PROJECT_ENV}",
    CICD_TEMPLATE_BASE: 'templates/cicd',
    // ... more defaults
]

❌ DON’T:

// Don't hardcode environment-specific values in defaults
def defaultConfigs = [
    ENV: 'prod'  // Wrong - should be per-project
]

4. Job Parameters

βœ… DO:

  • Provide clear descriptions
  • Use appropriate parameter types
  • Set sensible defaults

❌ DON’T:

  • Create too many parameters
  • Use unclear descriptions
  • Mix parameter types unnecessarily

5. Version Control

βœ… DO:

  • Commit all JobGenie changes
  • Use feature branches
  • Review changes before merging

❌ DON’T:

  • Make changes directly in production
  • Skip code review
  • Delete old configurations without migration

πŸ”§ Troubleshooting

Issue 1: Jobs Not Generated

Symptoms: Seed job runs but no jobs appear

Solutions:

  1. Check createjob flag: globalConfigs.createjob = true
  2. Verify JobGenie map structure
  3. Check Jenkins console logs
  4. Verify file path in seed job

Issue 2: Wrong Job Path

Symptoms: Jobs created in unexpected location

Solutions:

  1. Check DEPLOY_HOME variable
  2. Verify JOB_SUFFIX_MKDIR calculation
  3. Review folder creation logic

Issue 3: Missing Parameters

Symptoms: Expected parameters not appearing

Solutions:

  1. Verify JOB_PARAMS structure
  2. Check parameter type (string, choices, bool)
  3. Review pipelineGenerator function

Issue 4: Template Not Found

Symptoms: Jenkinsfile not found error

Solutions:

  1. Verify DEFAULT_JENKINSFILE path
  2. Check CONFIG_REPO and CONFIG_BRANCH
  3. Ensure Jenkinsfile exists in repository

Issue 5: Variable Resolution Issues

Symptoms: Variables not resolving correctly

Solutions:

  1. Check variable precedence
  2. Verify variable names (case-sensitive)
  3. Review configuration merging logic

πŸ“– Reference

Variable Reference

Variable Type Required Description
APP_REPO String Yes* Git repository name
APP_BRANCH String Yes* Git branch
appNames List Yes* List of service names
SERVICE String Yes** Service identifier
CICD_TEMPLATE_NAME String No Pipeline template name
DOCKER_BUILD_ARGS String No Docker build arguments
SSH_KEYS String No SSH key path
JOB_PARAMS List No Custom job parameters

*Required for standard application jobs **Required for custom jobs

Parameter Types

// String parameter
[ name: 'BRANCH', string: 'master', description: 'Git branch' ]

// Choice parameter
[ name: 'ENV', choices: ['dev', 'prod'], description: 'Environment' ]

// Boolean parameter
[ name: 'DRY_RUN', bool: false, description: 'Dry run mode' ]

// Dynamic choice parameter
[ name: 'ImageTag', choiceType: 'SINGLE_SELECT', arChoiceGroovy: '...' ]

πŸ“š Additional Resources

🧭 Navigation

Related Topics:


Maintained by the DevOps Team

β€œYour friendly Jenkins job generator”


Last Updated: January 15, 2024
Version: 1.0.0

Found this helpful?

Help us improve this documentation by sharing your feedback or suggesting improvements.