Continuous Delivery workflows often require deploying code from different branches (such as master, main, staging, or feature branches) dynamically without hardcoding branch names into build configurations. Parameterized Jenkins Pipelines enable developers and DevOps engineers to pass runtime variables—such as target environment, release tags, or Git branch names—directly into declarative pipeline scripts.
In this challenge, we configure a parameterized Jenkins Declarative Pipeline job named datacenter-webapp-job to deploy a static web application to App Server 1 (stapp01). The pipeline accepts a user-defined string parameter named BRANCH, fetches the remote repository updates, checks out the specified branch, and updates the web server document root (/var/www/html).
Key tasks accomplished:
App Server 1) with label stapp01 and remote root directory /home/sarah/jenkins_agent.datacenter-webapp-job and configuring a String Parameter BRANCH with description Branch to deploy.stapp01 and runs shell commands (git fetch, git checkout ${BRANCH}, git pull origin ${BRANCH}) inside /var/www/html.BRANCH = master, inspecting console execution logs, and verifying clean deployment completion.graph TD
subgraph UserInput ["User / Automation Trigger"]
Param["Build with Parameters<br/>BRANCH = master"]
end
subgraph JenkinsController ["Jenkins Controller"]
Job["Pipeline Job:<br/>datacenter-webapp-job"]
Script["Declarative Jenkinsfile<br/>agent { label 'stapp01' }"]
end
subgraph AppServer ["App Server 1: stapp01"]
Agent["Jenkins Agent Process<br/>Root: /home/sarah/jenkins_agent"]
GitRepo["Git Repository<br/>http://gitea:3000/sarah/web_app"]
WebRoot["Apache Web Root<br/>/var/www/html"]
Apache["Apache Web Server<br/>Port 8091"]
end
Param -->|"1. Submit Parameter"| Job
Job -->|"2. Inject BRANCH Parameter"| Script
Script -->|"3. Schedule on stapp01"| Agent
Agent -->|"4. git fetch origin"| GitRepo
Agent -->|"5. git checkout BRANCH"| WebRoot
Agent -->|"6. git pull origin BRANCH"| WebRoot
WebRoot -->|"7. Serve Updated Branch Content"| Apache
By checking This project is parameterized in the job configuration, Jenkins injects environment variables into the build process at runtime:
BRANCHBranch to deploysh), the parameter is accessed via environment variable syntax: ${BRANCH} or $BRANCH.To safely switch and pull branches inside an existing document root, the pipeline uses a three-step Git strategy:
git fetch origin: Synchronizes all remote branch refs from Gitea without modifying local files.git checkout ${BRANCH}: Switches the local web root working tree to the branch specified in the BRANCH parameter.git pull origin ${BRANCH}: Pulls the latest commits from the tracking branch on origin into /var/www/html.pipeline {
agent { label 'stapp01' }
stages {
stage('Deploy') {
steps {
sh '''
cd /var/www/html
git fetch origin
git checkout ${BRANCH}
git pull origin ${BRANCH}
'''
}
}
}
}
8080admin / Adm!n321App Server 1 (stapp01)http://gitea:3000/sarah/web_appPipeline, SSH Build Agents| Setting | Value |
|---|---|
| Node Name | App Server 1 |
| Node Label | stapp01 |
| Remote Root Directory | /home/sarah/jenkins_agent |
| Launch Method | Launch agents via SSH |
| Host | stapp01 |
| SSH Credentials | sarah |
| Pipeline Job Name | datacenter-webapp-job |
| Parameter Type | String Parameter |
| Parameter Name | BRANCH |
| Parameter Description | Branch to deploy |
| Pipeline Stage Name | Deploy |
| Web Server Document Root | /var/www/html |
adminAdm!n321
Navigate to Manage Jenkins -> Plugins -> Installed plugins and verify that both Pipeline and SSH Build Agents plugins are installed and enabled.

App Server 1 Agent NodeApp Server 1:
/home/sarah/jenkins_agentstapp01Launch agents via SSHstapp01sarahNon verifying Verification Strategy
On the Nodes overview page, confirm that App Server 1 is online and actively connected to the controller with label stapp01.

datacenter-webapp-jobdatacenter-webapp-job
BRANCHIn the project configuration under the General section:
BRANCHmaster)Branch to deploy
Scroll down to the Pipeline section, set Definition to Pipeline script, and paste the following Groovy pipeline script:
pipeline {
agent { label 'stapp01' }
stages {
stage('Deploy') {
steps {
sh '''
cd /var/www/html
git fetch origin
git checkout ${BRANCH}
git pull origin ${BRANCH}
'''
}
}
}
}
Click Save.

datacenter-webapp-job, click Build with Parameters in the left sidebar.master in the BRANCH parameter input field.
Open Console Output for Build #1 to confirm successful execution:
App Server 1 in workspace /home/sarah/jenkins_agent/workspace/datacenter-webapp-job.cd /var/www/html.git fetch origin.git checkout master (Switched to branch 'master').git pull origin master (From http://gitea:3000/sarah/web_app).Finished: SUCCESS.
pipeline {
agent {
label 'stapp01'
}
stages {
stage('Deploy') {
steps {
sh '''
cd /var/www/html
git fetch origin
git checkout ${BRANCH}
git pull origin ${BRANCH}
'''
}
}
}
}
App Server 1 active with label stapp01 and remote root /home/sarah/jenkins_agent.datacenter-webapp-job created in Jenkins.BRANCH and description Branch to deploy.agent { label 'stapp01' } and shell steps referencing ${BRANCH}.BRANCH = master./var/www/html.Finished: SUCCESS.