Day 81: Jenkins Multistage Pipeline | 100 Days of DevOps
Content
Today I worked on creating a Jenkins Multistage Pipeline for xFusionCorp Industries. The objective was to automate the deployment of a static website hosted in a Gitea repository and deploy it on App Server 1 using Jenkins Pipeline stages. The pipeline was required to run on a Jenkins Agent and validate the deployment by testing the website through the Load Balancer URL.
๐น What I Learned
Jenkins Multistage Pipelines
Jenkins Pipeline Stages
Configuring Jenkins SSH Agents
Automated Git-Based Deployments
Deploying Applications on Remote Servers
Validating Deployments with Automated Tests
Using Jenkins Agents for Distributed Builds
๐น Task Requirement
The development team at xFusionCorp Industries was developing a new static website and wanted Jenkins to automate its deployment.
The repository was already cloned on App Server 1 under:
/var/www/html
The Jenkins Pipeline needed to:
Update the website content in the Gitea repository
Deploy the latest code from the repository
Execute deployment on App Server 1 through a Jenkins Agent
Include two stages named:
Deploy
Test
Validate website accessibility through the Load Balancer URL
Jenkins Access Details
| Field | Value |
|---|---|
| Username | admin |
| Password | Adm!n321 |
Gitea Access Details
| Field | Value |
|---|---|
| Username | sarah |
| Password | Sarah_pass123 |
Deployment Requirements
| Requirement | Value |
|---|---|
| Pipeline Job | deploy-job |
| Agent Name | App Server 1 |
| Agent Label | stapp01 |
| Repository | web |
| Repository Location | /var/www/html |
| Agent Remote Root Directory | /home/sarah/jenkins_agent |
| Pipeline Stages | Deploy, Test |
| Validation URL | http://stlb01:8091 |
๐น Steps I Followed
1. Connected to App Server 1
Logged into App Server 1:
ssh sarah@stapp01
Authenticated using:
Sarah_pass123
Successfully connected to the server.
2. Verified Existing Website Content
Moved to the website directory:
cd /var/www/html
Verified contents:
ls
cat index.html
Output:
Welcome
This confirmed the existing website content before deployment.
3. Installed Java 17 on App Server 1
Verified the existing Java version:
java -version
Output:
openjdk version "11.0.20.1"
Installed OpenJDK 17:
sudo yum install -y java-17-openjdk
Authenticated using:
Sarah_pass123
Installation completed successfully.
Java is required for Jenkins agents to communicate with the Jenkins controller.
4. Accessed Jenkins
Clicked the Jenkins button available in the lab environment.
Logged in using:
Username: admin
Password: Adm!n321
Successfully accessed the Jenkins Dashboard.
5. Installed Required Jenkins Plugins
Navigated to:
Manage Jenkins
โ Plugins
Installed:
Git
Pipeline
SSH Build Agents
After installation:
Restarted Jenkins
Refreshed the browser
Logged in again
6. Added Jenkins Credentials
Navigated to:
Manage Jenkins
โ Credentials
โ System
โ Global Credentials
โ Add Credentials
Configured:
| Field | Value |
|---|---|
| Kind | Username with Password |
| Username | sarah |
| Password | Sarah_pass123 |
| ID | App Server 1 |
Saved the credentials.
7. Configured Jenkins Agent
Navigated to:
Manage Jenkins
โ Nodes
โ New Node
Configured:
| Field | Value |
|---|---|
| Name | App Server 1 |
| Remote Root Directory | /home/sarah/jenkins_agent |
| Labels | stapp01 |
| Launch Method | Launch agents via SSH |
| Host | stapp01 |
| Credentials | sarah |
| Host Key Verification | Non-verifying Verification Strategy |
Saved the configuration.
Jenkins successfully connected to the remote server.
Agent Status:
Connected
8. Created Jenkins Pipeline Job
Navigated to:
New Item
Entered:
deploy-job
Selected:
Pipeline
Clicked:
OK
9. Added Pipeline Script
Under:
Pipeline
โ Definition
โ Pipeline Script
Added:
pipeline {
agent { label 'stapp01' }
stages {
stage('Deploy') {
steps {
sh '''
cd /var/www/html
git pull origin master
'''
}
}
stage('Test') {
steps {
sh '''
curl -f http://stlb01:8091
'''
}
}
}
}
10. Understanding the Pipeline
Agent Section
agent { label 'stapp01' }
Ensures the pipeline runs only on the Jenkins Agent configured on App Server 1.
Deploy Stage
stage('Deploy')
The task explicitly required a stage named:
Deploy
This stage:
Moves to the existing repository
Pulls the latest code from Gitea
Updates the deployed website
Command executed:
cd /var/www/html
git pull origin master
Test Stage
stage('Test')
The task explicitly required a stage named:
Test
This stage validates that the application is working correctly after deployment.
Command executed:
curl -f http://stlb01:8091
The -f option ensures the build fails if the website is inaccessible or returns an error status.
11. Updated Website Content in Gitea
Clicked the Gitea button and logged in using:
Username: sarah
Password: Sarah_pass123
Opened repository:
sarah/web
Edited:
index.html
Changed content from:
Welcome
to:
Welcome to xFusionCorp Industries
Committed the changes to the:
master
branch.
12. Verified Website Before Deployment
Clicked the:
App
button.
Output:
Welcome
The old content was still displayed because deployment had not yet occurred.
13. Triggered Jenkins Build
Opened:
deploy-job
โ Build Now
Build Status:
SUCCESS
14. Verified Deploy Stage Output
Console Output:
git pull origin master
Output:
Updating 043a119..101ed3a
Fast-forward
index.html updated
This confirmed that Jenkins successfully pulled the latest changes from Gitea.
15. Verified Test Stage Output
Pipeline executed:
curl -f http://stlb01:8091
Output:
Welcome to xFusionCorp Industries
This confirmed that the application was accessible and serving the updated content.
16. Verified Build Result
Jenkins reported:
Last build (#2) SUCCESS
Last stable build (#2) SUCCESS
Last successful build (#2) SUCCESS
Pipeline execution completed successfully.
17. Verified Application
Clicked the:
App
button available in the lab environment.
Verified output:
Welcome to xFusionCorp Industries
Confirmed that the application was loading directly from:
http://stlb01:8091
and not from a subdirectory such as:
http://stlb01:8091/web
18. Verified Deployment on App Server
Connected to App Server 1:
cd /var/www/html
cat index.html
Output:
Welcome to xFusionCorp Industries
This confirmed the deployed content on the server matched the latest repository version.
๐น Simple Explanation of Jenkins Components Used
Jenkins Agent
A Jenkins Agent is a remote machine that executes build and deployment tasks.
In this task:
App Server 1
acted as the Jenkins Agent.
Agent Labels
Labels help Jenkins determine where jobs should run.
Example:
agent {
label 'stapp01'
}
This ensures deployment occurs only on App Server 1.
Pipeline Stages
Stages divide a pipeline into logical sections.
In this task:
Deploy
Test
Deploy updated the application.
Test verified the application was accessible after deployment.
Git-Based Deployment
Instead of cloning a repository during every build, the pipeline operated directly on the existing repository:
git pull origin master
This is faster and aligns with the repository structure provided by the task.
Deployment Validation
The Test stage used:
curl -f http://stlb01:8091
to ensure the application was reachable.
If the website returned an error or was unavailable, Jenkins would automatically fail the build.
Continuous Deployment
The deployment process was fully automated:
Developer updates code in Gitea
Jenkins runs on the remote agent
Latest code is pulled from Git
Website is deployed
Application is tested automatically
Deployment succeeds only if validation passes
๐น My Understanding
This task helped me understand how Jenkins Multistage Pipelines can automate both deployment and validation in a single workflow. Instead of only deploying code, the pipeline also verified application availability before reporting success.
๐น What I Found Interesting
I found it interesting that Jenkins could perform deployment and validation as separate stages within the same pipeline. The Deploy stage handled the application update, while the Test stage acted as a quality gate by verifying the website through the Load Balancer URL.
๐ Full notes: GitHub link