Home Portfolio Blog Courses

Quick Reference Guide - Jenkins as Code

Quick reference for common tasks and configurations in Jenkins as Code

Updated Jan 15, 2024
6 min read
Beginner
tools

Quick Reference Guide

Quick reference for common tasks and configurations in Jenkins as Code

📋 Table of Contents


🚀 Common Commands

Ansible Commands

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

# Check connectivity
ansible target_host -m ping

# Run with verbose output
ansible-playbook packer.yml -e "target_host=..." -vvv

# Dry run (check mode)
ansible-playbook packer.yml -e "target_host=..." --check

Git Commands

# Create feature branch
git checkout -b feature/onboard-new-service

# Commit changes
git add amazon/mcloud/nonprod/jobs/mcloud-nonprod-jobs.yml
git commit -m "Onboard new-service-api"

# Push and create PR
git push origin feature/onboard-new-service

Jenkins Commands

# Check Jenkins service
systemctl status jenkins

# View Jenkins logs
tail -f /var/log/jenkins/jenkins.log

# Restart Jenkins
systemctl restart jenkins

⚙️ Configuration Quick Reference

Essential Ansible Variables

# Jenkins Version
jenkins_version: 2.528.2

# Jenkins Home
jenkins_home: "/var/lib/jenkins"

# Project Name
jenkins_project_name: amazon

# Jenkins URL
jenkins_location:
  url: "https://jenkins.mcloud.com/"
  adminAddress: "mcloud-jenkins@mcloud.com"

# Security
jenkins_securityRealm:
  local:
    allowsSignup: false
    users:
      - id: "admin"
        password: "Admin@123"

User Access Configuration

# Read Users
overall_read_users:
  amazon:
    mcloud:
      - user: "dev"
    qa:
      - user: "qa-user"

# Admin Users
overall_admin_users:
  devops_managers:
    - user: "hari_25585"
    - user: "admin"

JobGenie Default Config

# Default section in YAML job definition file
jobgenie:
  default:
    HOME_DIR: prod
    GROUP: "v4"
    ENV: "prod"
  jobs:
    # Jobs defined here

🎩 JobGenie Quick Examples

Simple Application Job

# File: amazon/mcloud/prod/jobs/mcloud-prod-jobs.yml
jobgenie:
  default:
    HOME_DIR: prod
    GROUP: "v4"
    ENV: "prod"
  jobs:
    - NAME: "my-service"
      PARAMETERS:
        - { name: 'GitBranch', string: 'master', description: 'Application branch.' }
      CONFIGS:
        APP_REPO: "my-app"
        APP_BRANCH: "master"

Multiple Jobs in One File

jobgenie:
  default:
    HOME_DIR: prod
    GROUP: "v4"
    ENV: "prod"
  jobs:
    - NAME: "service-a"
      CONFIGS:
        APP_REPO: "monorepo"
        APP_BRANCH: "main"
    - NAME: "service-b"
      CONFIGS:
        APP_REPO: "monorepo"
        APP_BRANCH: "main"
    - NAME: "service-c"
      CONFIGS:
        APP_REPO: "monorepo"
        APP_BRANCH: "main"

Custom Job with Parameters

jobgenie:
  default:
    HOME_DIR: prod
    GROUP: "v4"
    ENV: "prod"
  jobs:
    - NAME: "custom-service"
      PARAMETERS:
        - { name: 'TAG', string: 'latest', description: 'Deployment tag.' }
        - { name: 'Environment', choices: ['dev', 'prod'], description: 'Target environment.' }
      CONFIGS:
        SERVICE: "custom-service"
        CICD_TEMPLATE_NAME: "custom-template"
        APP_REPO: "custom-app"
        APP_BRANCH: "main"

Advanced Configuration

jobgenie:
  default:
    HOME_DIR: prod
    GROUP: "v4"
    ENV: "prod"
  jobs:
    - NAME: "my-service"
      PARAMETERS:
        - { name: 'GitBranch', string: 'develop', description: 'Application branch.' }
      CONFIGS:
        APP_REPO: "my-app"
        APP_BRANCH: "develop"
        DOCKER_BUILD_ARGS: "ENV,TECHTEAM"
        DOCKERFILE_PATH: "services/Dockerfile"
        SSH_KEYS: "default:/opt/jenkins/keys/prod_key_rsa"

🔧 Troubleshooting Quick Fixes

Jenkins Not Accessible

# Check service
systemctl status jenkins

# Check port
netstat -tlnp | grep 8080

# Check logs
tail -f /var/log/jenkins/jenkins.log

Configuration Not Applied

  1. Reload Configuration as Code:
    • Navigate to: amazon/manage-infra/Reload-ConfigAsCode
    • Run job
  2. Check Configuration:
    • Navigate to: Manage JenkinsConfiguration as Code

Jobs Not Generated

  1. Verify YAML file naming:
    • Must end with -jobs.yml or -jobs.yaml
    • Path: {org}/{project}/{env}/jobs/{project}-{env}-jobs.yml
  2. Verify YAML syntax:
    jobgenie:
      default:
        HOME_DIR: prod
        GROUP: "v4"
        ENV: "prod"
      jobs:
        - NAME: "my-service"
          CONFIGS:
            APP_REPO: "my-app"
    
  3. Check seed job logs:
    • View console output
    • Look for YAML parsing errors
    • Verify file path matches expected structure

Permission Denied

  1. Check user in configuration:
    overall_read_users:
      amazon:
        mcloud:
          - user: "username"
    
  2. Verify role patterns match job paths

  3. Test as user to verify access

📚 Additional Resources

🧭 Navigation

Related Topics:

Jenkins

  • Jenkins URL: https://jenkins.mcloud.com/
  • Configuration as Code: Manage JenkinsConfiguration as Code
  • Credentials: Manage JenkinsCredentials

Git Repositories

  • mCloud-Jenkins: https://github.com/HarryTheDevOpsGuy/mCloud-Jenkins.git
  • mCloud-infra: https://github.com/HarryTheDevOpsGuy/mCloud-infra.git

Support

  • Email: devops-admin@example.com
  • Slack: #devops-alerts

📝 Common Workflows

Onboard New Service

  1. Edit YAML job definition file:
    # File: amazon/mcloud/nonprod/jobs/mcloud-nonprod-jobs.yml
    jobgenie:
      default:
        HOME_DIR: nonprod
        GROUP: "v4"
        ENV: "stage"
      jobs:
        - NAME: "new-service-api"
          PARAMETERS:
            - { name: 'GitBranch', string: 'develop', description: 'Development branch.' }
          CONFIGS:
            APP_REPO: "new-service"
            APP_BRANCH: "develop"
    
  2. Commit and push:
    git add amazon/mcloud/nonprod/jobs/mcloud-nonprod-jobs.yml
    git commit -m "Onboard new-service-api"
    git push origin feature/onboard-new-service
    
  3. Run seed job:
    • Navigate to: 0-JobGenie-Generator
    • Set GitBranch parameter to your branch
    • Click Build
  4. Verify job created:
    • Check: amazon/mcloud/nonprod/deploy/v4/stage/new-service-api

Update Configuration

  1. Edit Ansible variables:
    vim group_vars/packer_al2023_aarch64_devops_jenkins.yml
    
  2. Run Ansible playbook:
    ansible-playbook packer.yml \
      -e "target_host=packer_al2023_aarch64_devops_jenkins" \
      -t deploy
    
  3. Reload Configuration as Code:
    • Run: amazon/manage-infra/Reload-ConfigAsCode

Add New User

  1. Edit Ansible variables:
    overall_read_users:
      amazon:
        mcloud:
          - user: "new-user"
    
  2. Run Ansible playbook:
    ansible-playbook packer.yml \
      -e "target_host=packer_al2023_aarch64_devops_jenkins" \
      -t deploy
    
  3. Reload Configuration as Code

🎯 Quick Checklist

Initial Setup

  • Ansible playbook configured
  • Jenkins server provisioned
  • Configuration as Code loaded
  • Credentials added
  • Seed jobs created

Onboarding Service

  • JobGenie config created
  • Changes committed to Git
  • Seed job run successfully
  • Jobs generated correctly
  • Test build successful

Maintenance

  • Regular backups configured
  • Monitoring enabled
  • Security audit completed
  • Documentation updated
  • Team trained

Maintained by the DevOps Team

Quick reference for common tasks

Related Documentation

More from Tools

Architecture Documentation - Jenkins as Code

Comprehensive architecture guide for Jenkins as Code automation framework

Best Practices Guide - Jenkins as Code

Recommended practices for using Jenkins as Code automation framework

DevOps as a Service - Automated CI/CD Management

Transforming Jenkins from a bottleneck to a self-service platform for develop...

JobGenie - Complete Job Creation Guide

Step-by-step guide to creating and configuring Jenkins jobs using JobGenie YA...

JobGenie - Complete Guide

Your friendly Jenkins job generator - Comprehensive guide to JobGenie job gen...

Jenkins as Code - Complete Setup Guide

Step-by-step guide to set up Jenkins as Code with plugins, access control, an...

Jenkins as Code - Enterprise CI/CD Automation

Complete Jenkins automation framework with Infrastructure as Code, Configurat...

BG Deployer

Automated blue-green deployment for zero-downtime AWS releases

DevOps Tools & Utilities | Hari Prasad

Custom-built DevOps tools for automation, monitoring, deployment, and security

JobGenie Getting Started

Your DevOps Superpower Unleashed - Transform CI/CD with YAML-driven Jenkins j...

JobGenie

Your DevOps Superpower Unleashed - Transform CI/CD with YAML-driven Jenkins j...

mCert

SSL certificate monitoring with Slack/email alerts & Telegram

mTracker

Real-time Linux user activity monitoring with Slack notifications

mWatcher

Server health monitoring for CPU, memory, disk with alerting

Sample DevOps Tool Documentation

A comprehensive guide to using our sample DevOps tool for automation and moni...

Typography Demo

Demonstration of enhanced typography features in the documentation template

Found this helpful?

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