Day 77: Jenkins Deploy Pipeline | 100 Days of DevOps
Content
Today I worked on creating a Jenkins Pipeline job to automate the deployment of a static website for xFusionCorp Industries. The objective was to fetch the latest code from a Git repository hosted on Gitea and deploy it automatically to an Apache web server running on an application server.
๐น What I Learned
- Installing and Managing Jenkins Plugins
- Configuring Jenkins SSH Agents
- Creating and Managing Jenkins Credentials
- Connecting Jenkins with Remote Linux Servers
- Setting Up Jenkins Pipeline Jobs
- Using Declarative Pipeline Syntax
- Cloning Git Repositories in Jenkins
- Executing Shell Commands Through Jenkins Agents
- Deploying Static Websites to Apache Web Servers
- Understanding Jenkins Agent Labels
- Automating Application Deployment
๐น Task Requirement
The DevOps team at xFusionCorp Industries needed a Jenkins Pipeline to deploy a static website hosted in a Git repository. The latest application code had to be pulled from Gitea and deployed directly to the document root of Apache running on App Server 1.
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 | devops-webapp-job |
| Agent Label | stapp01 |
| Agent Name | App Server |
| Repository | web_app |
| Deployment Path | /var/www/html |
| Pipeline Stage | Deploy |
๐น Steps I Followed
1. Accessed Jenkins Web Interface
Clicked the Jenkins button available in the lab environment.
This opened the Jenkins login page.
2. Logged into Jenkins
Entered the administrator credentials:
Username
admin
Password
Adm!n321
Successfully logged into the Jenkins Dashboard.
3. Installed Required Plugins
Navigated to:
Manage Jenkins
โ Plugins
Installed the following plugins:
- SSH Build Agents
- Pipeline
After installation:
- Restarted Jenkins
- Refreshed the browser
- Logged in again
4. Added Jenkins Credentials
Navigated to:
Manage Jenkins
โ Credentials
โ System
โ Global Credentials
โ Add Credentials
Configured:
| Field | Value |
|---|---|
| Kind | Username with Password |
| Username | tony |
| Password | Ir0nM@n |
| ID | stapp01 |
Saved the credentials.
5. Connected to App Server 1
From the jump host:
ssh tony@stapp01
Authenticated using:
Ir0nM@n
6. Installed Java on the Application Server
Since Jenkins agents require Java, I installed OpenJDK 17:
sudo yum install java-17-openjdk -y
Installation completed successfully.
7. Fixed Directory Ownership
The repository was already present under:
/var/www/html
To prevent Jenkins agent launch failures, I changed ownership of the web directory:
cd /var/www
sudo chown -R tony html/
Verified:
ls -l
Output:
drwxr-xr-x 1 tony sarah 4096 html
This ensured Jenkins could access and write files during deployment.
8. Configured Jenkins Agent
Navigated to:
Manage Jenkins
โ Nodes
โ New Node
Configured the agent:
| Field | Value |
|---|---|
| Name | App Server |
| Remote Root Directory | /var/www/html |
| Labels | stapp01 |
| Launch Method | Launch agents via SSH |
| Host | stapp01 |
| Credentials | stapp01 |
| Host Key Verification | Non-verifying Verification Strategy |
Saved the configuration.
Jenkins successfully connected to the remote server and launched the agent.
9. Retrieved Repository Information from Gitea
Logged into Gitea using:
Username
sarah
Password
Sarah_pass123
Located the repository:
web_app
Repository URL:
https://3000-port-w7smhgyo6w2z2oy7.labs.kodekloud.com/sarah/web_app.git
This URL would be used in the Jenkins Pipeline.
10. Created Jenkins Pipeline Job
From the Jenkins Dashboard:
New Item
Entered:
devops-webapp-job
Selected:
Pipeline
Clicked:
OK
The Pipeline configuration page opened.
11. Added Pipeline Script
Under:
Pipeline
โ Definition
โ Pipeline Script
Added the following script:
pipeline {
agent { label 'stapp01' }
stages {
stage('Deploy') {
steps {
sh 'rm -rf /tmp/web_app'
sh 'git clone https://3000-port-w7smhgyo6w2z2oy7.labs.kodekloud.com/sarah/web_app.git /tmp/web_app'
sh 'ls -la /tmp/web_app'
sh 'echo "Ir0nM@n" | sudo -S cp -r /tmp/web_app/* /var/www/html/'
sh 'rm -rf /tmp/web_app'
}
}
}
}
12. Understanding the Pipeline
Agent Section
agent { label 'stapp01' }
Ensures the pipeline runs on the configured App Server agent.
Deploy Stage
stage('Deploy')
Creates the required deployment stage.
The task specifically required the stage name to be:
Deploy
(case-sensitive)
Remove Existing Temporary Files
rm -rf /tmp/web_app
Ensures a clean deployment workspace.
Clone Latest Source Code
git clone <repository-url> /tmp/web_app
Downloads the latest application source code.
Verify Repository Content
ls -la /tmp/web_app
Confirms repository files were cloned successfully.
Deploy Website Files
sudo cp -r /tmp/web_app/* /var/www/html/
Copies application files into Apache's document root.
Cleanup
rm -rf /tmp/web_app
Removes temporary deployment files.
13. Saved the Job
Clicked:
Apply
Then:
Save
The Pipeline job was successfully created.
14. Triggered the Pipeline
Opened:
devops-webapp-job
โ Build Now
Jenkins immediately started executing the deployment.
15. Verified Build Success
Opened:
Build History
โ Latest Build
โ Console Output
Observed output similar to:
Cloning into '/tmp/web_app'...
+ ls -la /tmp/web_app
index.html
+ sudo cp -r /tmp/web_app/* /var/www/html/
Finished: SUCCESS
This confirmed the deployment completed successfully.
16. Verified Application Deployment
Clicked the:
App
button available in the lab environment.
The application loaded successfully.
Output:
Welcome to xFusionCorp Industries!
This confirmed that the website was being served directly from:
/var/www/html
and not from a subdirectory.
๐น Simple Explanation of Jenkins Components Used
Jenkins Agent
A Jenkins Agent is a remote machine that executes build and deployment jobs.
In this task:
App Server 1
acted as the Jenkins Agent.
Labels
Labels help Jenkins determine where a job should run.
Example:
agent {
label 'stapp01'
}
This ensures the pipeline executes only on the specified server.
Pipeline
A Pipeline defines the entire CI/CD workflow as code.
Benefits:
- Version controlled
- Repeatable
- Automated
- Easier to maintain
Declarative Pipeline
The script used follows Jenkins Declarative Pipeline syntax.
Structure:
pipeline {
agent
stages
steps
}
This syntax is easier to read and maintain.
Git Clone
git clone repository_url
Downloads the latest version of application source code from Git.
This guarantees deployment of the most recent changes.
Apache Document Root
Apache serves web pages from:
/var/www/html
Any files copied here become accessible through the web server.
Continuous Deployment
This pipeline automates deployment by:
- Fetching code
- Copying files to the web server
- Publishing the latest version
without manual intervention.
๐น My Understanding
This task helped me understand how Jenkins Pipelines can automate application deployments. By combining Git repositories, Jenkins agents, and shell commands, it becomes possible to deploy applications consistently and reliably. Using a dedicated agent also ensures deployment activities are performed directly on the target server.
๐น What I Found Interesting
I found it interesting that a complete deployment workflow could be implemented with a relatively small Jenkins Pipeline. The ability to define deployment logic as code makes the process reproducible, easy to modify, and suitable for larger CI/CD implementations. It also demonstrated how Jenkins can seamlessly integrate with Git repositories and remote servers to automate application delivery.
๐ Full notes: GitHub link