Getting Started with DevOps: Building Jenkins Pipelines Step by Step

Listen to this Post

DevOps is all about continuous improvement, and Jenkins is a powerful tool to automate your workflows. Here’s how you can start small and grow your expertise.

You Should Know:

1. Setting Up Jenkins

First, install Jenkins on your system:

 For Ubuntu/Debian
sudo apt update
sudo apt install openjdk-11-jdk -y
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y
sudo systemctl start jenkins
sudo systemctl enable jenkins

2. Creating Your First Pipeline

A basic `Jenkinsfile` to print “Hello World”:

pipeline {
agent any
stages {
stage('Hello') {
steps {
echo 'Hello World'
}
}
}
}

3. Adding Variables and Steps

Expand your pipeline with environment variables:

pipeline {
agent any
environment {
GREETING = 'Welcome to DevOps!'
}
stages {
stage('Greet') {
steps {
echo "${env.GREETING}"
}
}
}
}

4. Automating Daily Pipeline Checks

Use a cron job to trigger Jenkins daily:

pipeline {
triggers {
cron('0 22   ') // Runs at 10 PM daily
}
agent any
stages {
stage('Build') {
steps {
sh 'echo "Running nightly build..."'
}
}
}
}

5. Error Handling & Debugging

Check pipeline success/failure and retry:

post {
failure {
echo "Pipeline failed! Retrying..."
retry(3) {
sh './retry-script.sh'
}
}
success {
echo "Pipeline succeeded!"
}
}

What Undercode Say:

DevOps is about iterative learning. Start small—automate a simple task, then expand. Jenkins pipelines help enforce consistency. Use Linux commands (grep, awk, cron) to monitor logs and schedule jobs. Windows users can leverage `PowerShell` for automation.

Expected Output:

A working Jenkins pipeline that runs daily, logs output, and recovers from failures.

Relevant URLs:

References:

Reported By: Wanderson Silva – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 TelegramFeatured Image