JobGenie Getting Started

Your DevOps Superpower Unleashed - Transform CI/CD with YAML-driven Jenkins job automation

Updated Jan 15, 2025
15 min read
Intermediate
tools

JobGenie Getting Started Guide

β€œSoch Wahi, Approach Nai” - Redefining CI/CD Automation

Welcome to JobGenie! This guide will walk you through integrating JobGenie into a new Jenkins instance and getting your first YAML-driven jobs up and running.

πŸ“‹ Table of Contents


Overview

JobGenie is a robust solution for managing Jenkins as code, transforming complex CI/CD pipeline creation into simple YAML definitions. It combines powerful tools and utilities to deliver production-grade automation from zero to deployment.

Core Components

JobGenie leverages two main components:

  1. Ansible: Automates Jenkins installation and configuration according to project needs. The Ansible solution is fully flexible and can configure any aspect of a Linux server running Jenkins.

  2. Jenkins Plugins: Utilizes essential plugins to supercharge Jenkins configuration and job creation:

    • JobDSL Plugin: Generates jobs programmatically from code
    • Configuration as Code (JCasC): Manages Jenkins system configuration as YAML
    • Role Strategy Plugin: Implements role-based access control
    • Pipeline Plugin: Enables declarative and scripted pipelines
    • Git Plugin: Integrates Git repositories for source control

Key Benefits

  • βœ… Zero Manual Configuration: Define jobs in YAML, JobGenie creates them automatically
  • βœ… GitOps Native: Full version control and audit trail for all configurations
  • βœ… Scalable: Handle hundreds of jobs with minimal effort
  • βœ… Consistent: Single source of truth eliminates configuration drift
  • βœ… Auditable: Complete Git history of all changes

Prerequisites

System Requirements

Server Requirements

  • OS: Amazon Linux 2023 / Amazon Linux 2 (ARM64 or x86_64) or any Linux distribution
  • CPU: Minimum 2 cores, recommended 4+ cores
  • RAM: Minimum 4GB, recommended 8GB+
  • Disk: Minimum 50GB, recommended 100GB+
  • Network: Internet access for plugin downloads and Git operations

Software Requirements

  • Jenkins: Version 2.528.2 or higher (LTS recommended)
  • Java: JDK 11 or JDK 17 (required by Jenkins)
  • Git: Latest version for repository access
  • Ansible: 2.9 or higher (for automated setup)
  • Python: 3.8 or higher (for Ansible)

Access Requirements

  • SSH access to Jenkins server with sudo/root privileges
  • Git repository access (SSH keys or HTTPS credentials)
  • Jenkins admin credentials

Required Jenkins Plugins

The following plugins must be installed in your Jenkins instance:

Required Plugins:
  - job-dsl                    # Job generation engine
  - configuration-as-code      # System configuration management
  - role-strategy             # Role-based access control
  - workflow-aggregator       # Pipeline support
  - git                       # Git integration
  - credentials-binding        # Secure credential management
  - build-user-vars-plugin    # Build user variables

Optional but Recommended:
  - docker-slaves            # Docker-based build agents
  - docker-workflow          # Docker pipeline support
  - ansicolor                # Colored console output
  - favorite                 # Favorite jobs
  - aws-java-sdk-secretsmanager  # AWS Secrets Manager integration

Integration Methods

There are two ways to integrate JobGenie into a new Jenkins instance:

  1. Automated Setup with Ansible (Recommended for production)
  2. Manual Integration (For quick setup or existing Jenkins)

Choose the method that best fits your environment and requirements.


Method 1: Automated Setup with Ansible

This method uses Ansible playbooks to automate the entire Jenkins setup, including JobGenie integration.

Step 1: Clone Required Repositories

# Clone the infrastructure repository (contains Ansible automation)
git clone https://github.com/HarryTheDevOpsGuy/mCloud-infra.git
cd mCloud-infra/ansible

# Clone the Jenkins configuration repository
cd ..
git clone https://github.com/HarryTheDevOpsGuy/mCloud-Jenkins.git
cd mCloud-Jenkins

Step 2: Configure Ansible Variables

Edit the Ansible group variables file to configure your Jenkins instance:

cd ../mCloud-infra/ansible
vim group_vars/packer_al2023_aarch64_devops_jenkins.yml

Essential Configuration

# Jenkins Version
jenkins_version: 2.528.2
jenkins_home: "/var/lib/jenkins"

# Jenkins Plugins (includes JobGenie requirements)
jenkins_plugins:
  - docker-slaves
  - docker-workflow
  - ansicolor
  - google-login
  - aws-java-sdk-secretsmanager
  - favorite
  - job-dsl                    # Required for JobGenie
  - configuration-as-code     # Required for JobGenie
  - role-strategy             # Required for JobGenie
  - workflow-aggregator       # Required for pipelines
  - git                       # Required for Git integration
  - credentials-binding       # Required for secure credentials

# Jenkins URL Configuration
jenkins_location:
  url: "https://jenkins.example.com/"
  adminAddress: "jenkins-admin@example.com"

# Security Configuration
jenkins_securityRealm:
  local:
    allowsSignup: false
    enableCaptcha: false
    users:
      - id: "admin"
        name: "admin"
        password: "${ADMIN_PASSWORD}"  # Use environment variable or Ansible Vault

# JobGenie Seed Job Configuration
jenkins_onboarding:
  global:
    common:
      mkdir: ["common/manage-infra"]
      jobs: []
        
  amazon:
    mcloud:
      jobs: []
      env: ["nonprod", "prod"]

# Access Control Configuration
overall_read_users:
  amazon:
    mcloud:
      - user: "dev-user"
    qa:
      - user: "qa-user"

overall_admin_users:
  devops_managers:
    - user: "hari_25585"
    - user: "admin"

Step 3: Configure Global Libraries

Set up shared libraries for JobGenie:

jenkins_glabal_libraries:
  - name: "sharedPipelineUtils"
    branch: "master"
    path: "sharedlibs"
    creds: "jenkins_repo_key"
    repo: "git@github.com:HarryTheDevOpsGuy/mCloud-Jenkins.git"

Step 4: Run Ansible Playbook

Execute the Ansible playbook to install and configure Jenkins:

# Test connectivity first (dry-run)
ansible-playbook packer.yml \
  -e "target_host=packer_al2023_aarch64_devops_jenkins" \
  --check

# Run full deployment
ansible-playbook packer.yml \
  -e "target_host=packer_al2023_aarch64_devops_jenkins" \
  -t deploy,monitoring

Playbook Tags

  • deploy: Jenkins installation and configuration
  • monitoring: Monitoring stack setup
  • install_stacks: Install specific stacks only

Step 5: Post-Deployment Configuration

After the Ansible playbook completes:

  1. Access Jenkins: Navigate to https://jenkins.example.com/
  2. Login: Use admin credentials configured in Ansible variables
  3. Verify Configuration: Check that Configuration as Code is loaded
  4. Verify Plugins: Ensure all required plugins are installed
  5. Verify Seed Jobs: Check that JobGenie seed jobs exist

Step 6: Configure Git Credentials

Add SSH key credential for Git repository access:

  1. Navigate to: Manage Jenkins β†’ Credentials β†’ System β†’ Global credentials
  2. Click Add Credentials
  3. Configure:
    • Kind: SSH Username with private key
    • ID: jenkins_repo_key
    • Username: git
    • Private Key: Upload SSH private key or paste content
  4. Click OK

Method 2: Manual Integration

If you have an existing Jenkins instance or prefer manual setup, follow these steps.

Step 1: Install Required Plugins

  1. Navigate to: Manage Jenkins β†’ Manage Plugins β†’ Available
  2. Search and install the following plugins:
    • job-dsl
    • configuration-as-code
    • role-strategy
    • workflow-aggregator
    • git
    • credentials-binding
    • build-user-vars-plugin
  3. Click Install without restart or Download now and install after restart
  4. Restart Jenkins if prompted

Step 2: Configure Jenkins System Settings

Configure Git Settings

  1. Navigate to: Manage Jenkins β†’ Configure System
  2. Under Git, configure:
    • Git executable: /usr/bin/git (or your Git path)
    • Create account: Configure if needed
  3. Click Save

Configure Global Libraries

  1. Navigate to: Manage Jenkins β†’ Configure System β†’ Global Pipeline Libraries
  2. Click Add
  3. Configure:
    • Name: sharedPipelineUtils
    • Default version: master
    • Retrieval method: Modern SCM
    • Source Code Management: Git
      • Repository URL: git@github.com:HarryTheDevOpsGuy/mCloud-Jenkins.git
      • Credentials: Select jenkins_repo_key (create if needed)
      • Library Path: sharedlibs
  4. Click Save

Step 3: Configure Git Credentials

  1. Navigate to: Manage Jenkins β†’ Credentials β†’ System β†’ Global credentials
  2. Click Add Credentials
  3. Configure:
    • Kind: SSH Username with private key
    • ID: jenkins_repo_key
    • Username: git
    • Private Key: Upload or paste SSH private key
  4. Click OK

Step 4: Create JobGenie Seed Job

  1. Navigate to: New Item
  2. Enter name: 0-JobGenie-Generator
  3. Select: Pipeline
  4. Click OK

Configure Seed Job

General Configuration:

  • Check This project is parameterized
  • Add String Parameter:
    • Name: GitBranch
    • Default Value: master
    • Description: Config repository branch.

Pipeline Configuration:

  • Definition: Pipeline script from SCM
  • SCM: Git
  • Repository URL: https://github.com/HarryTheDevOpsGuy/mCloud-Jenkins.git
  • Credentials: Select jenkins_repo_key
  • Branch: ${GitBranch}
  • Script Path: JobGenie/pipelines/jobGenie.groovy

Pipeline Script (Alternative - Direct Script):

node {
  label "linux-slave"
  checkout scm

  def allEnvVars = [ message: 'Hello from pipeline', credentials: 'SECRET', TECHTEAM: 'mcloud' ] + env.getEnvironment()
  ['BUILD_NUMBER', 'BUILD_DISPLAY_NAME', 'JOB_NAME', 'JOB_BASE_NAME', 'WORKSPACE', 'BUILD_URL'].each { var -> 
    if (env."$var") { allEnvVars[var] = env."$var" }
  }

  dir('mCloud-Jenkins') {
    git url: 'https://github.com/HarryTheDevOpsGuy/mCloud-Jenkins.git', 
        branch: "${GitBranch}", 
        credentialsId: 'jenkins_repo_key'
  }

  jobDsl targets: ["JobGenie/pipelines/*.groovy"].join('\n'),
    additionalClasspath: 'mCloud-Jenkins/sharedlibs/src',
    removedJobAction: 'DELETE',
    removedViewAction: 'DELETE',
    additionalParameters: allEnvVars
}
  1. Click Save

Step 5: Run Seed Job

  1. Navigate to the 0-JobGenie-Generator job
  2. Click Build with Parameters
  3. Set GitBranch to master (or your config branch)
  4. Click Build
  5. Monitor the build console output for job generation

Directory Structure

JobGenie follows a well-organized directory structure designed to manage multiple organizations’ infrastructure, especially Kubernetes infrastructure.

Standard Structure

{organization}/{project}/{environment}/
β”œβ”€β”€ jobs/
β”‚   └── {project}-{environment}-jobs.yml
β”œβ”€β”€ jenkinsfiles/
β”‚   β”œβ”€β”€ default/
β”‚   └── sample/
└── helm-values/
    β”œβ”€β”€ apps/
    └── infra/

Job File Path Convention

{organization}/{project}/{environment}/jobs/{project}-{environment}-jobs.yml

Examples:

  • amazon/mcloud/prod/jobs/mcloud-prod-jobs.yml
  • amazon/mcloud/nonprod/jobs/mcloud-nonprod-jobs.yml
  • global/common/nonprod/jobs/common-nonprod-jobs.yml

Create Directory Structure

You can create the standard directory structure using:

# Create organization-specific structure
mkdir -p amazon/{mcloud,xcloud}/{nonprod,prod}/{jenkinsfiles/{default,sample},jobs,helm-values/{apps,infra}}

# Create global/common structure
mkdir -p global/common/{nonprod,prod}/{jenkinsfiles/{default,sample},jobs,helm-values/{apps,infra}}

Directory Structure Benefits

  • Organized: Clear separation by organization, project, and environment
  • Scalable: Easy to add new projects and environments
  • Maintainable: Consistent structure across all projects
  • Kubernetes-Ready: Designed for managing Kubernetes infrastructure

Creating Your First Job

Now that JobGenie is integrated, let’s create your first YAML-driven job.

Step 1: Create Job Definition File

Create a YAML file following the naming convention:

cd mCloud-Jenkins
mkdir -p amazon/myproject/prod/jobs
vim amazon/myproject/prod/jobs/myproject-prod-jobs.yml

Step 2: Define Your Job

Add the following content to your YAML file:

jobgenie:
  default:
    HOME_DIR: prod
    GROUP: "v2"
    ENV: "prod"
  jobs:
    - NAME: "hello-world-service"
      PARAMETERS:
        - { name: 'GitBranch', string: 'main', description: 'Application git branch.' }
      CONFIGS:
        APP_REPO: "hello-world"
        APP_BRANCH: "main"
        DOCKER_BUILD_ARGS: "ENV,SERVICE"

Step 3: Commit and Push

git add amazon/myproject/prod/jobs/myproject-prod-jobs.yml
git commit -m "Add hello-world-service job definition"
git push origin main

Step 4: Run JobGenie Seed Job

  1. Navigate to: amazon/common/0-JobGenie-Generator (or your seed job)
  2. Click Build with Parameters
  3. Set GitBranch to your branch (e.g., main)
  4. Click Build
  5. JobGenie will scan, parse, and create your jobs automatically

Step 5: Verify Job Creation

Check Jenkins for the newly created job:

  • Path: amazon/myproject/prod/deploy/v2/prod/hello-world-service
  • Status: Job should be ready to build immediately
  • Configuration: Verify parameters and pipeline configuration

Verification and Testing

Verify JobGenie Integration

  1. Check Seed Job: Verify seed job exists and runs successfully
  2. Check Console Output: Review seed job console for any errors
  3. Verify Job Generation: Confirm jobs are created in expected locations
  4. Test Job Execution: Run a generated job to ensure it works

Common Verification Steps

# Check Jenkins logs
sudo tail -f /var/lib/jenkins/logs/jenkins.log

# Verify plugins are installed
curl -s http://localhost:8080/pluginManager/api/json?depth=1 | jq '.plugins[] | select(.shortName | contains("job-dsl"))'

# Check JobDSL script approval
# Navigate to: Manage Jenkins β†’ In-process Script Approval

Test Job Definition

Before committing, validate your YAML syntax:

# Install yamllint (if not installed)
pip install yamllint

# Validate YAML syntax
yamllint amazon/myproject/prod/jobs/myproject-prod-jobs.yml

Next Steps

Now that JobGenie is integrated, explore these advanced features:

  1. Multi-Environment Jobs: Create jobs for dev, staging, and prod
  2. Parameterized Builds: Add choice parameters, boolean parameters
  3. Custom Templates: Use custom pipeline templates
  4. Freestyle Jobs: Create freestyle jobs for specialized tasks
  5. Advanced Configuration: Explore environment variable injection, custom paths

Troubleshooting

Issue: Seed Job Fails to Run

Symptoms: Seed job fails with errors

Solutions:

  • Verify all required plugins are installed
  • Check Git credentials are configured correctly
  • Verify repository URL and branch are correct
  • Review console output for specific error messages
  • Ensure JobDSL script approval is granted

Issue: Jobs Not Created

Symptoms: Seed job runs successfully but no jobs are created

Solutions:

  • Verify YAML file naming: must end with -jobs.yml or -jobs.yaml
  • Check YAML syntax is valid (use yamllint)
  • Verify file path matches expected structure
  • Review seed job console output for parsing errors
  • Ensure jobgenie: key is present at root level

Issue: YAML Parsing Errors

Symptoms: Seed job fails with YAML parsing errors

Solutions:

  • Validate YAML syntax using online validators or yamllint
  • Check indentation (must be spaces, not tabs)
  • Verify all required fields are present (default, jobs)
  • Ensure job names don’t contain invalid characters
  • Review console output for specific line numbers

Issue: Jobs Created in Wrong Location

Symptoms: Jobs appear in unexpected folders

Solutions:

  • Check HOME_DIR, GROUP, and ENV in default section
  • Verify PIPELINE_PATH if using custom paths
  • Review job name structure (slashes create subfolders)
  • Ensure environment variables are set correctly

Issue: Git Credentials Not Working

Symptoms: Seed job fails to checkout repository

Solutions:

  • Verify SSH key is correctly configured
  • Test SSH access manually: ssh -T git@github.com
  • Check credential ID matches configuration
  • Ensure private key format is correct (PEM format)
  • Verify user has repository access

Getting Help

If you encounter issues not covered here:

  1. Check the Full Documentation
  2. Review seed job console output
  3. Check Jenkins system logs
  4. Contact the maintainer: HarryTheDevOpsGuy@gmail.com

Summary

You’ve successfully integrated JobGenie into your Jenkins instance! Here’s what you’ve accomplished:

βœ… Installed Required Plugins: JobDSL, Configuration as Code, Role Strategy
βœ… Configured Git Credentials: Set up repository access
βœ… Created Seed Job: JobGenie generator job is ready
βœ… Created Directory Structure: Organized structure for job definitions
βœ… Created First Job: YAML-driven job definition

Next: Start creating more job definitions and explore advanced features!


**Need Help?** Check out the [JobGenie Full Documentation](/docs/tools/jobgenie/) for more detailed information, examples, and best practices.

Built with ❀️ by the DevOps Team

β€œSoch Wahi, Approach Nai” - Same Vision, New Approach

From Zero to Hero in Minutes, Not Months πŸš€

Found this helpful?

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