Modern Continuous Integration and Continuous Deployment (CI/CD) pipelines enforce software quality by structuring build workflows into distinct, sequential stages. Jenkins Multistage Declarative Pipelines allow DevOps engineers to define end-to-end delivery pipelines as code, separating deployment logic from automated health check testing. If a failure occurs in an early stage (such as deployment), execution is halted immediately, preventing downstream tests from running on an unstable release.
In this challenge, we build a multi-stage Declarative Pipeline job named deploy-job targeting App Server 1 (stapp01). The pipeline incorporates two core stages:
stapp01), navigates to Apache’s web document root (/var/www/html), and pulls the latest application code from the Gitea Git repository (master branch).curl --fail --silent --show-error. If the web server returns an HTTP error or is unreachable, the stage throws an error and fails the pipeline.Key tasks accomplished:
sarah under Jenkins Global Credentials management to enable secure agent authentication.stapp01 as SSH user sarah, upgrading OpenJDK 11 to Java 17 (java-17-openjdk), and registering stapp01 as an SSH agent node with remote root /home/sarah/jenkins_agent.deploy-job) bound to label stapp01 with explicit Deploy and Test stages.curl in the Test stage.Welcome to xFusionCorp Industries) in Gitea, triggering deploy-job, and verifying stage completion in Jenkins Stage View.graph TD
subgraph SCM ["Gitea Source Control"]
GitRepo["Git Repository: sarah/web.git<br/>Branch: master"]
end
subgraph JenkinsController ["Jenkins Controller"]
Credentials["Jenkins Store<br/>Secret Credentials for sarah"]
PipelineJob["Declarative Pipeline:<br/>deploy-job"]
StageView["Jenkins Stage View<br/>Deploy and Test Stages"]
end
subgraph AppServer ["App Server 1: stapp01"]
Java17["Java 17 Runtime<br/>java-17-openjdk"]
Agent["Jenkins Agent: sarah<br/>Remote Root: /home/sarah/jenkins_agent"]
WebRoot["Apache Web Root<br/>/var/www/html"]
Apache["Apache Web Server<br/>Port 8091"]
end
Credentials -->|"Authenticate SSH Agent"| Agent
GitRepo -->|"1. Commit and Push Code"| PipelineJob
PipelineJob -->|"2. Schedule Execution on stapp01"| Agent
Agent -->|"3. Stage 1: Deploy - git pull origin master"| WebRoot
WebRoot -->|"4. Stage 2: Test - curl --fail APP_URL"| Apache
Apache -->|"5. HTTP 200 OK Response"| StageView
Declarative Pipelines organize execution blocks clearly:
pipeline { ... }: Root wrapper for the pipeline workflow.agent { label 'stapp01' }: Restricts execution of all pipeline stages to agent nodes carrying label stapp01.environment { ... }: Defines global pipeline variables (e.g., APP_URL, REPO_URL, DEPLOY_DIR).stages { ... }: Encloses sequential stage blocks (Deploy, Test).pipeline {
agent {
label 'stapp01'
}
environment {
APP_URL = 'http://stapp01:8091/'
REPO_URL = 'http://gitea:3000/sarah/web.git'
DEPLOY_DIR = '/var/www/html'
}
stages {
stage ('Deploy') {
steps {
sh """
cd ${DEPLOY_DIR}
git pull origin master
"""
}
}
stage ('Test') {
steps {
sh """
echo 'Testing ${APP_URL}...'
sleep 5
curl --fail --silent --show-error ${APP_URL} || (echo 'APPLICATION IS DOWN' && exit 1)
"""
}
}
}
}
The Test stage uses specific curl flags to guarantee deployment verification:
--fail (-f): Causes curl to return exit code 22 on HTTP error status codes (4xx/5xx).--silent (-s): Suppresses transfer progress bars while preserving error messages when paired with --show-error (-S).|| (echo 'APPLICATION IS DOWN' && exit 1): Catches network timeouts or HTTP errors, prints a failure message to the console log, and explicitly exits with code 1 to fail the build.8080admin / Adm!n321App Server 1 (stapp01)sarah (username & password)http://gitea:3000/sarah/web.gitSSH Build Agents, Pipeline| Setting | Value |
|---|---|
| Node Name | App Server 1 |
| Node Label | stapp01 |
| Remote Root Directory | /home/sarah/jenkins_agent |
| Agent Launch Method | Launch agents via SSH |
| Host | stapp01 |
| Credentials | sarah (SSH Username & Password) |
| Pipeline Job Name | deploy-job |
| Pipeline Stages | Deploy, Test |
| Deploy Target Directory | /var/www/html |
| Test Endpoint | Application HTTP Web URL |
adminAdm!n321

sarahsarahsarahSSH Credentials for sarah on App Server 1

stapp01 & Configure Agent Nodestapp01 as user sarah from jumphost:ssh sarah@stapp01
java --version
Output:
openjdk 11.0.20.1 2023-08-24 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS)
yum:sudo yum install java-17-openjdk -y
java --version
Output:
openjdk 17.0.18 2026-01-20 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.18.0.8-2) (build 17.0.18+8-LTS)

App Server 1/home/sarah/jenkins_agentstapp01stapp01sarah secret credential created in Step 2

deploy-job)deploy-job.Select Pipeline and click OK.
Pipeline script.pipeline {
agent {
label 'stapp01'
}
environment {
APP_URL = 'http://stapp01:8091/'
REPO_URL = 'http://gitea:3000/sarah/web.git'
DEPLOY_DIR = '/var/www/html'
}
stages {
stage ('Deploy') {
steps {
sh """
cd ${DEPLOY_DIR}
git pull origin master
"""
}
}
stage ('Test') {
steps {
sh """
echo 'Testing ${APP_URL}...'
sleep 5
curl --fail --silent --show-error ${APP_URL} || (echo 'APPLICATION IS DOWN' && exit 1)
"""
}
}
}
}

stapp01 local workspace.index.html in the master branch of the web repository:cd /home/sarah/web
echo "Welcome to xFusionCorp Industries" > index.html
git add index.html
git commit -m "Update web content for day 81 challenge"
git push origin master

Verify the web application content before triggering the pipeline (shows old content):
deploy-job and click Build Now.Monitor the Stage View to confirm both Deploy and Test stages pass with green status indicator.

curl:curl http://stapp01:8091
Response:
Welcome to xFusionCorp Industries
| Checkpoint | Expected Result | Status |
|---|---|---|
| Java 17 Runtime | java --version returns OpenJDK 17 on stapp01 |
PASS |
| Secret Credentials | Credential sarah created under Global credentials |
PASS |
| SSH Build Agent | Node App Server 1 with label stapp01 is Online |
PASS |
| Pipeline Definition | Job deploy-job configured with Declarative Groovy script |
PASS |
| Deploy Stage | Executes git pull origin master inside /var/www/html |
PASS |
| Test Stage | curl --fail completes with exit code 0 |
PASS |
| Stage View Matrix | Green execution status across Deploy and Test stages |
PASS |
| Live App Content | Application returns Welcome to xFusionCorp Industries |
PASS |
In this challenge, we successfully designed and executed a Jenkins Multistage Declarative Pipeline:
sarah.App Server 1 (stapp01) with Java 17 and bound it as a Jenkins agent.deploy-job with Deploy and Test stages targeting label stapp01.curl --fail in the Test stage to confirm post-deployment application health.deploy-job, and confirmed green Stage View status alongside updated application response.