๐ Jenkins CI/CD Server on AlmaLinux: Automate Your Software Delivery Pipeline
Welcome to the world of continuous integration and delivery! ๐ Ready to automate your entire software pipeline? Jenkins is the most popular open-source automation server that makes CI/CD a breeze! Itโs the platform that transforms manual deployments into automated workflows! Think of it as your development teamโs best friend that never sleeps! ๐โจ
๐ค Why is Jenkins Important?
Jenkins revolutionizes software delivery! ๐ Hereโs why itโs amazing:
- ๐ Continuous Integration - Automatically build and test code!
- ๐ฆ Continuous Delivery - Deploy to production seamlessly!
- ๐ 1000+ Plugins - Integrate with everything!
- ๐ Pipeline as Code - Version control your workflows!
- ๐ฏ Distributed Builds - Scale across multiple machines!
- ๐ Completely Free - Open source forever!
Itโs like having a robot army for your deployments! ๐ฐ
๐ฏ What You Need
Before building your CI/CD pipeline, ensure you have:
- โ AlmaLinux 9 server
- โ Root or sudo access
- โ At least 2GB RAM (4GB recommended)
- โ 2 CPU cores minimum
- โ 10GB free disk space
- โ Java 11 or newer
- โ Love for automation! ๐
๐ Step 1: System Preparation - Getting Ready!
Letโs prepare AlmaLinux 9 for Jenkins! ๐๏ธ
# Update system packages
sudo dnf update -y
# Install Java 11 (Jenkins requirement)
sudo dnf install -y java-11-openjdk java-11-openjdk-devel
# Verify Java installation
java -version
# Should show: openjdk version "11.0.x"
# Set JAVA_HOME environment variable
echo 'export JAVA_HOME=/usr/lib/jvm/java-11-openjdk' >> ~/.bashrc
echo 'export PATH=$JAVA_HOME/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
# Verify JAVA_HOME
echo $JAVA_HOME
# Should show: /usr/lib/jvm/java-11-openjdk
# Install additional tools
sudo dnf install -y wget git curl unzip
Configure firewall for Jenkins:
# Open Jenkins port
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
# Verify port is open
sudo firewall-cmd --list-ports
# Should show: 8080/tcp
Perfect! System is ready! ๐ฏ
๐ง Step 2: Installing Jenkins - The Official Way!
Letโs install Jenkins from the official repository! ๐
Add Jenkins Repository:
# Import Jenkins GPG key
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
# Add Jenkins repository
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
# Verify repository
sudo dnf repolist | grep jenkins
# Should show: jenkins repository
Install Jenkins:
# Install Jenkins
sudo dnf install -y jenkins
# Enable Jenkins service
sudo systemctl enable jenkins
# Start Jenkins
sudo systemctl start jenkins
# Check status
sudo systemctl status jenkins
# Should show: active (running)
# View initial admin password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
# Save this password! You'll need it!
๐ Step 3: Initial Setup - Your CI/CD Dashboard!
Time to configure Jenkins! ๐ฎ
Access Jenkins Web UI:
# Get your server IP
ip addr show | grep inet
# Note your server IP address
# Access Jenkins
# URL: http://your-server-ip:8080
# Enter the initial admin password from earlier
Setup Wizard Steps:
-
Unlock Jenkins:
- Enter initial admin password
- Click โContinueโ
-
Install Plugins:
- Select โInstall suggested pluginsโ
- Wait for plugins to install (5-10 minutes)
- Plugins include Git, Pipeline, Credentials, etc.
-
Create Admin User:
- Username:
admin
- Password:
YourSecurePassword
- Full name:
Jenkins Admin
- Email:
[email protected]
- Username:
-
Instance Configuration:
- Jenkins URL:
http://your-server-ip:8080
- Click โSave and Finishโ
- Jenkins URL:
-
Start Using Jenkins! ๐
Dashboard shows:
- ๐ New Item - Create jobs/pipelines
- ๐ฅ People - User management
- ๐ Build History - Execution logs
- ๐ง Manage Jenkins - Configuration
- ๐ My Views - Custom dashboards
โ Step 4: Creating Your First Pipeline - Letโs Build!
Time to create your first CI/CD pipeline! ๐ฏ
Create Freestyle Project:
- Click โNew Itemโ
- Enter name:
Hello-World-Build
- Select: โFreestyle projectโ
- Click โOKโ
Configure Build:
-
General Section:
- Description:
My first Jenkins build
- Check: โDiscard old buildsโ
- Max builds:
10
- Description:
-
Source Code Management:
- Select: โGitโ
- Repository URL:
https://github.com/example/hello-world.git
- Branch:
*/main
-
Build Triggers:
- Check: โPoll SCMโ
- Schedule:
H/5 * * * *
(every 5 minutes)
-
Build Steps:
- Click โAdd build stepโ โ โExecute shellโ
echo "=== Starting Build ===" echo "Build number: $BUILD_NUMBER" echo "Workspace: $WORKSPACE" # Example build commands echo "Running tests..." # npm test echo "Building application..." # npm run build echo "Build completed successfully!"
-
Save the job
Run the Build:
- Click โBuild Nowโ ๐
- Watch build progress in Build History
- Click build number for details
- View โConsole Outputโ for logs
๐ Step 5: Creating Pipeline as Code - Modern CI/CD!
Letโs create a declarative pipeline! ๐ฏ
Create Pipeline Job:
- New Item โ Name:
Application-Pipeline
- Select: โPipelineโ
- Click โOKโ
Write Jenkinsfile:
In Pipeline section, add:
pipeline {
agent any
environment {
APP_NAME = 'MyApp'
APP_VERSION = '1.0.0'
}
stages {
stage('Checkout') {
steps {
echo '=== Checking out code ==='
git branch: 'main',
url: 'https://github.com/example/myapp.git'
}
}
stage('Build') {
steps {
echo '=== Building application ==='
sh '''
echo "Building ${APP_NAME} version ${APP_VERSION}"
# npm install
# npm run build
'''
}
}
stage('Test') {
steps {
echo '=== Running tests ==='
sh '''
echo "Testing application..."
# npm test
# npm run test:coverage
'''
}
}
stage('Deploy to Staging') {
steps {
echo '=== Deploying to staging ==='
sh '''
echo "Deploying to staging server..."
# scp -r dist/* user@staging:/var/www/
# ssh user@staging "sudo systemctl restart app"
'''
}
}
stage('Approval') {
steps {
input message: 'Deploy to production?',
ok: 'Deploy'
}
}
stage('Deploy to Production') {
steps {
echo '=== Deploying to production ==='
sh '''
echo "Deploying to production..."
# scp -r dist/* user@prod:/var/www/
# ssh user@prod "sudo systemctl restart app"
'''
}
}
}
post {
success {
echo 'Pipeline completed successfully!'
// Send success notification
}
failure {
echo 'Pipeline failed!'
// Send failure alert
}
always {
echo 'Cleaning up workspace...'
cleanWs()
}
}
}
Save and Run Pipeline:
- Save the pipeline
- Click โBuild Nowโ
- Watch stages execute in Stage View
- Approve deployment when prompted
๐ฎ Quick Examples
Example 1: Docker Build Pipeline
pipeline {
agent any
stages {
stage('Build Docker Image') {
steps {
script {
docker.build("myapp:${env.BUILD_NUMBER}")
}
}
}
stage('Push to Registry') {
steps {
script {
docker.withRegistry('https://registry.example.com', 'docker-creds') {
docker.image("myapp:${env.BUILD_NUMBER}").push()
docker.image("myapp:${env.BUILD_NUMBER}").push('latest')
}
}
}
}
stage('Deploy Container') {
steps {
sh '''
docker stop myapp || true
docker rm myapp || true
docker run -d --name myapp -p 3000:3000 myapp:${BUILD_NUMBER}
'''
}
}
}
}
Example 2: Multi-Branch Pipeline
Create Jenkinsfile
in your repository:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo "Building branch: ${env.BRANCH_NAME}"
sh 'make build'
}
}
stage('Test') {
steps {
sh 'make test'
}
}
stage('Deploy') {
when {
branch 'main'
}
steps {
echo 'Deploying to production...'
sh 'make deploy'
}
}
}
}
Then create Multi-branch Pipeline in Jenkins to auto-discover branches!
Example 3: Parallel Execution
pipeline {
agent any
stages {
stage('Parallel Tests') {
parallel {
stage('Unit Tests') {
steps {
sh 'npm run test:unit'
}
}
stage('Integration Tests') {
steps {
sh 'npm run test:integration'
}
}
stage('E2E Tests') {
steps {
sh 'npm run test:e2e'
}
}
}
}
}
}
๐จ Fix Common Problems
Problem 1: Jenkins Wonโt Start
Symptom: Service fails to start ๐ฐ
Fix:
# Check Jenkins logs
sudo journalctl -u jenkins -n 50
# Common issue: Java not found
which java
# If not found, reinstall Java
# Check port conflict
sudo netstat -tlnp | grep 8080
# If occupied, change port in:
sudo vi /etc/sysconfig/jenkins
# JENKINS_PORT="8081"
# Restart Jenkins
sudo systemctl restart jenkins
Problem 2: Build Failures
Symptom: Jobs fail immediately ๐ด
Fix:
# Check workspace permissions
sudo chown -R jenkins:jenkins /var/lib/jenkins/workspace
# Install build tools
sudo dnf install -y nodejs npm maven gradle
# Add Jenkins to docker group (if using Docker)
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
# Check environment variables
# In job configuration, add:
# Environment variables:
# PATH+EXTRA=/usr/local/bin:/opt/tools/bin
Problem 3: Plugin Issues
Symptom: Plugins wonโt install or update ๐
Fix:
# Update Jenkins
sudo dnf update jenkins
# Clear plugin cache
sudo rm -rf /var/lib/jenkins/plugins/*.tmp
sudo rm -rf /var/lib/jenkins/plugins/*.bak
# Restart Jenkins
sudo systemctl restart jenkins
# Manual plugin install
# Download .hpi file from https://plugins.jenkins.io/
# Upload via Manage Jenkins โ Manage Plugins โ Advanced
๐ Simple Commands Summary
Task | Location/Command | Purpose |
---|---|---|
Start Jenkins | sudo systemctl start jenkins | Start service |
Stop Jenkins | sudo systemctl stop jenkins | Stop service |
View logs | sudo journalctl -u jenkins -f | Monitor logs |
Initial password | sudo cat /var/lib/jenkins/secrets/initialAdminPassword | First login |
Backup | tar -czf jenkins-backup.tar.gz /var/lib/jenkins/ | Backup data |
Plugin list | Manage Jenkins โ Plugin Manager | View plugins |
Create job | New Item โ Select type | New automation |
View builds | Build History | Execution logs |
System info | Manage Jenkins โ System Information | Debug info |
๐ก Tips for Success
๐ Performance Optimization
Make Jenkins super fast:
# Increase heap memory
sudo vi /etc/sysconfig/jenkins
# JENKINS_JAVA_OPTIONS="-Xmx2g -Xms1g"
# Enable build executors
# Manage Jenkins โ Configure System
# # of executors: 4
# Use pipeline caching
# In Jenkinsfile:
options {
skipDefaultCheckout()
timestamps()
buildDiscarder(logRotator(numToKeepStr: '10'))
}
๐ Security Best Practices
Keep Jenkins secure:
- Enable security - Use matrix-based security! ๐
- HTTPS only - Configure SSL certificates! ๐
- Strong passwords - Enforce password policy! ๐ก๏ธ
- Limit access - Use role-based permissions! ๐ฅ
- Regular updates - Keep Jenkins updated! ๐ฆ
# Setup HTTPS with reverse proxy
sudo dnf install -y nginx
# Configure nginx
cat << 'EOF' > /etc/nginx/conf.d/jenkins.conf
server {
listen 443 ssl;
server_name jenkins.example.com;
ssl_certificate /etc/ssl/certs/jenkins.crt;
ssl_certificate_key /etc/ssl/private/jenkins.key;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
EOF
sudo systemctl restart nginx
๐ Monitoring and Backup
Keep Jenkins healthy:
# Automated backup script
cat << 'EOF' > /usr/local/bin/backup-jenkins.sh
#!/bin/bash
BACKUP_DIR="/backup/jenkins"
DATE=$(date +%Y%m%d)
# Create backup directory
mkdir -p $BACKUP_DIR
# Stop Jenkins
sudo systemctl stop jenkins
# Backup Jenkins home
tar -czf $BACKUP_DIR/jenkins-$DATE.tar.gz /var/lib/jenkins/
# Start Jenkins
sudo systemctl start jenkins
# Keep only last 7 backups
find $BACKUP_DIR -name "*.tar.gz" -mtime +7 -delete
echo "Backup completed: jenkins-$DATE.tar.gz"
EOF
chmod +x /usr/local/bin/backup-jenkins.sh
# Add to cron: 0 2 * * * /usr/local/bin/backup-jenkins.sh
๐ What You Learned
Youโre now a Jenkins CI/CD expert! ๐ Youโve successfully:
- โ Installed Jenkins on AlmaLinux 9
- โ Configured initial setup
- โ Created freestyle projects
- โ Built pipelines as code
- โ Set up continuous integration
- โ Implemented deployment workflows
- โ Mastered automation pipelines
Your CI/CD platform is production-ready! ๐
๐ฏ Why This Matters
Jenkins transforms software delivery! With your CI/CD server, you can:
- ๐ Deploy faster - Automate everything!
- ๐ก๏ธ Reduce errors - Consistent processes!
- ๐ Track everything - Full visibility!
- ๐ฅ Collaborate better - Shared pipelines!
- ๐ฐ Save time - Let Jenkins do the work!
Youโre not just building software - youโre automating the entire delivery pipeline! Every commit is tested, every deployment is tracked! ๐ญ
Keep automating, keep delivering, and remember - with Jenkins, continuous delivery is just a pipeline away! โญ
May your builds be green and your deployments smooth! ๐๐ฏ๐