Setup and Configuration Guide - Jenkins as Code
Step-by-step guide to setting up Jenkins as Code automation framework
Setup and Configuration Guide
Step-by-step guide to setting up Jenkins as Code automation framework
📋 Table of Contents
- Prerequisites
- Initial Setup
- Jenkins Configuration
- JobGenie Setup
- Verification
- Post-Setup Configuration
- Troubleshooting
🔧 Prerequisites
System Requirements
Server Requirements
- OS: Amazon Linux 2023 / Amazon Linux 2 (ARM64 or x86_64)
- CPU: Minimum 2 cores, recommended 4+ cores
- RAM: Minimum 4GB, recommended 8GB+
- Disk: Minimum 50GB, recommended 100GB+
- Network: Internet access for plugin downloads
Software Requirements
- Ansible: 2.9 or higher
- Python: 3.8 or higher
- Git: Latest version
- Docker: For containerized builds (optional)
- AWS CLI: For ECR/ECS integration (optional)
Access Requirements
- SSH access to target server
- Sudo/root privileges
- Git repository access
- AWS credentials (if using AWS services)
Network Requirements
- Outbound HTTPS (443) for plugin downloads
- Outbound SSH (22) for Git operations
- Inbound HTTPS (443) for Jenkins web UI
- Inbound SSH (22) for server management
🚀 Initial Setup
Step 1: Clone Repositories
# Clone mCloud-infra (Ansible automation)
git clone https://github.com/HarryTheDevOpsGuy/mCloud-infra.git
cd mCloud-infra/ansible
# Clone mCloud-Jenkins (Jenkins configs)
git clone https://github.com/HarryTheDevOpsGuy/mCloud-Jenkins.git
cd ../mCloud-Jenkins
Step 2: Configure Ansible Variables
Edit the Ansible group variables file:
cd ../mCloud-infra/ansible
vim group_vars/packer_al2023_aarch64_devops_jenkins.yml
Essential Configuration
# Jenkins Version
jenkins_version: 2.528.2
# Jenkins Home Directory
jenkins_home: "/var/lib/jenkins"
# Jenkins Plugins
jenkins_plugins:
- docker-slaves
- docker-workflow
- ansicolor
- google-login
- aws-java-sdk-secretsmanager
- favorite
# Jenkins URL
jenkins_location:
url: "https://jenkins.mcloud.com/"
adminAddress: "mcloud-jenkins@mcloud.com"
# Security Configuration
jenkins_securityRealm:
local:
allowsSignup: false
users:
- id: "admin"
name: "admin"
password: "Admin@123" # Change this!
Step 3: Configure User Access
Define User Roles
# Read Users
overall_read_users:
amazon:
mcloud:
- user: "dev"
qa:
- user: "qa-user"
# Write Users
overall_write_users:
devops_users: []
# Admin Users
overall_admin_users:
devops_managers:
- user: "Harry"
- user: "admin"
Step 4: Configure Onboarding Projects
jenkins_onboarding:
amazon:
common:
jobs:
- NAME: "0-JobGenie-Generator"
PARAMETERS:
- { name: 'GitBranch', string: 'master', description: 'Dev application git branch.' }
VARS:
CONFIG_BRANCH: "master"
CONFIG_REPO: "https://github.com/HarryTheDevOpsGuy/mCloud-Jenkins.git"
JENKINS_GIT_KEY: 'jenkins_repo_key'
mcloud:
jobs:
- NAME: "0-mCloud-DevOps"
PARAMETERS:
- { name: 'GitBranch', string: 'master', description: 'Dev application git branch.' }
VARS:
CONFIG_REPO: "https://github.com/HarryTheDevOpsGuy/mCloud-Jenkins.git"
JENKINS_GIT_KEY: 'jenkins_repo_key'
env: ["nonprod", "prod"]
Step 5: Run Ansible Playbook
# Test connection first
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 configurationmonitoring: Monitoring stack setupinstall_stacks: Install specific stacks only
⚙️ Jenkins Configuration
Step 1: Access Jenkins
- Open browser:
https://jenkins.mcloud.com/ - Login with admin credentials
- Verify Configuration as Code is loaded
Step 2: Verify Configuration
Check System Configuration
- Navigate to: Manage Jenkins → System Information
- Verify:
- Jenkins version
- Number of executors
- Plugin versions
Check Security Configuration
- Navigate to: Manage Jenkins → Configure Global Security
- Verify:
- Security realm configured
- Authorization strategy (Role-Based)
- Roles and permissions
Step 3: Configure Credentials
Add Git Credentials
- Navigate to: Manage Jenkins → Credentials
- Add SSH key credential:
- Kind: SSH Username with private key
- ID:
jenkins_repo_key - Username:
git - Private Key: Upload or paste SSH key
Add AWS Credentials (if needed)
- Add AWS credentials:
- Kind: AWS Credentials
- ID:
aws_credentials - Access Key ID: Your AWS access key
- Secret Access Key: Your AWS secret key
Step 4: Verify Seed Jobs
- Navigate to:
amazon/common/0-JobGenie-Generator - Verify job exists and is configured
- Run job to generate initial jobs
🎩 JobGenie Setup
Step 1: Create JobGenie Configuration
Create or edit JobGenie file:
cd mCloud-Jenkins
vim amazon/mcloud/nonprod/pipelines/jobs/JobGenie.groovy
Step 2: Define Default Configurations
def defaultConfigs = [
// Required variables
EKS_CLUSTER_NAME: "${defaultConfigs.PROJECT_NAME}-eks-${defaultConfigs.PROJECT_ENV}",
CICD_TEMPLATE_BASE: 'templates/cicd',
CICD_BASE: "${defaultConfigs.HOME_DIR}/jenkinsfiles",
VALUES_YMLBASE: "${defaultConfigs.HOME_DIR}/helm-values",
IMAGE_ECR: "${globalConfigs.awsAccountId}.dkr.ecr.${globalConfigs.region}.amazonaws.com",
// Optional variables
GROUP: "v2",
ENV: "stage",
HOSTED_ZONE: 'example.com',
APP_PORT: '8080',
ARGOCD_ENDPOINT: 'argocd.example.com'
]
Step 3: Define JobGenie Map
def jobGenie = [
"mcloud": [
[
APP_REPO: 'my-application',
APP_BRANCH: 'master',
appNames: ['my-service']
]
]
]
Step 4: Commit and Push
git add amazon/mcloud/nonprod/pipelines/jobs/JobGenie.groovy
git commit -m "Initial JobGenie configuration"
git push origin master
Step 5: Run Seed Job
- Navigate to:
amazon/mcloud/nonprod/0-mCloud-DevOps - Click Build with Parameters
- Set
GitBranchto your branch - Click Build
- Monitor job execution
- Verify jobs are created
✅ Verification
Checklist
Infrastructure Verification
- Jenkins server accessible
- HTTPS working
- All plugins installed
- Monitoring stack running
Configuration Verification
- Configuration as Code loaded
- Security configured correctly
- Credentials added
- Global libraries configured
Job Generation Verification
- Seed jobs exist
- Seed jobs run successfully
- Jobs generated correctly
- Job folders created
Access Verification
- Admin can access all features
- Users have correct permissions
- Role-based access working
- Audit trail enabled
Test Job Execution
- Create Test Job
def jobGenie = [ "mcloud": [ [ APP_REPO: 'test-app', APP_BRANCH: 'master', appNames: ['test-service'] ] ] ] - Run Seed Job
- Verify Job Created
- Run Generated Job
- Check Build Logs
🔐 Post-Setup Configuration
1. Configure Monitoring
Verify Monitoring Stack
# Check Telegraf
systemctl status telegraf
# Check Filebeat
systemctl status filebeat
Configure Log Aggregation
- Set up ELK stack endpoint
- Configure Filebeat output
- Verify log shipping
2. Configure Backup
S3 Backup Configuration
jenkins_s3_backup_dir: "s3://bucket-name/path/to/backup"
Automated Backup
- Set up cron job for backups
- Configure backup retention
- Test restore procedure
3. Configure Notifications
Slack Integration
jenkins_slack_notifier:
botUser: false
room: "devops-alerts"
teamDomain: "https://example.slack.com/"
tokenCredentialId: "SlackToken"
Email Configuration
- Configure SMTP settings
- Set up email notifications
- Test email delivery
4. Configure External Integrations
ArgoCD Integration
- Configure ArgoCD endpoint
- Set up credentials
- Test deployment workflow
ECR Integration
- Configure AWS credentials
- Set up ECR repositories
- Test image push/pull
🔧 Troubleshooting
Issue 1: Ansible Playbook Fails
Symptoms: Playbook execution fails
Solutions:
# Check connectivity
ansible target_host -m ping
# Run with verbose output
ansible-playbook packer.yml -e "target_host=..." -vvv
# Check Ansible version
ansible --version
Issue 2: Jenkins Not Accessible
Symptoms: Cannot access Jenkins web UI
Solutions:
# Check Jenkins service
systemctl status jenkins
# Check port
netstat -tlnp | grep 8080
# Check firewall
firewall-cmd --list-ports
# Check logs
tail -f /var/log/jenkins/jenkins.log
Issue 3: Configuration Not Applied
Symptoms: Changes not reflected in Jenkins
Solutions:
- Reload Configuration as Code:
- Navigate to:
amazon/manage-infra/Reload-ConfigAsCode - Run job
- Navigate to:
- Check Configuration as Code:
- Navigate to: Manage Jenkins → Configuration as Code
- View current configuration
- Verify Ansible variables:
- Check variable file syntax
- Verify template rendering
Issue 4: Jobs Not Generated
Symptoms: Seed job runs but no jobs created
Solutions:
- Check JobGenie syntax:
// Verify map structure def jobGenie = [ /* ... */ ] - Check seed job logs:
- View console output
- Look for errors
- Verify file paths:
- Check JobGenie file location
- Verify file permissions
Issue 5: Permission Denied
Symptoms: Users cannot access jobs
Solutions:
- Check role configuration:
overall_read_users: amazon: mcloud: - user: "username" - Verify pattern matching:
- Check job path patterns
- Verify role patterns
- Test permissions:
- Login as test user
- Verify access
📚 Next Steps
After setup is complete:
- Onboard First Team
- Create JobGenie configuration
- Run seed job
- Verify jobs created
- Create Documentation
- Team-specific guides
- Runbooks
- Troubleshooting guides
- Set Up Monitoring
- Configure alerts
- Set up dashboards
- Review metrics
- Plan Scaling
- Identify additional teams
- Plan onboarding schedule
- Allocate resources
📚 Additional Resources
📖 Related Documentation
- 🏠 Main Documentation - Complete Jenkins as Code framework overview
- 🏗️ Architecture Documentation - System architecture and design
- ⚙️ JobGenie Guide - JobGenie usage and examples
- 🚀 DevOps as a Service - Self-service CI/CD platform guide
- ✅ Best Practices - Recommended practices and guidelines
- 📝 Quick Reference - Quick reference guide
🧭 Navigation
Related Topics:
- Review Architecture to understand the system before setup
- Learn JobGenie for job configuration after setup
- Follow Best Practices during setup
Maintained by the DevOps Team
Related Documentation
More from Tools
Related by Tags
No related documentation found by tags
Related Blog Posts
OpenResty Production Setup: Supercharge with Lua-Based Metrics and Monitoring
Complete guide to deploying production-ready OpenResty with advanced Lua-based metrics collection...
KEDA on EKS: Complete Guide to Event-Driven Autoscaling with Real-World Examples
Master KEDA implementation on Amazon EKS with comprehensive examples for multiple scaling scenari...
AIOps: AI-Powered DevOps Automation and Intelligent Operations
Comprehensive guide to implementing AIOps - using AI and machine learning to transform DevOps pra...
Related Tools & Projects
BG Deployer
Automated blue-green deployment for zero-downtime AWS releases
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
gCrypt
Git-crypt wrapper for secure file encryption & access management
Interactive Tools
AWS VPC Designer, EKS Cost Calculator, and more utilities
External Resources
Quick Actions
Found this helpful?
Help us improve this documentation by sharing your feedback or suggesting improvements.