Files
kodekloud-engineer/100 - days of devops/devops-71-80.md

927 lines
39 KiB
Markdown

## Task 71
Some new requirements have come up to install and configure some packages on the Nautilus infrastructure under Stratos Datacenter. The Nautilus DevOps team installed and configured a new Jenkins server so they wanted to create a Jenkins job to automate this task. Find below more details and complete the task accordingly:
1. Access the Jenkins UI by clicking on the Jenkins button in the top bar. Log in using the credentials: username admin and password Adm!n321.
2. Create a new Jenkins job named install-packages and configure it with the following specifications:
Add a string parameter named PACKAGE.
Configure the job to install a package specified in the $PACKAGE parameter on the storage server (Stratos Datacenter).
Build the job at least once (e.g. with parameter PACKAGE=vim-enhanced) so the package is installed on the Storage server and can be verified.
### Solution
# Jenkins job: install-packages
## Step 1 — Log in
Click **Jenkins** → login `admin` / `Adm!n321`.
## Step 2 — Install the "SSH" plugin (Publish Over SSH)
**Manage Jenkins → Plugins → Available plugins** → search **"SSH"** (the "Publish Over SSH" plugin) → check → **Download now and install after restart**.
Wait for restart, wait for login page, log back in.
## Step 3 — Configure the SSH remote host (storage server)
**Manage Jenkins → System** (Configure System) → scroll to **Publish over SSH** section → **SSH Servers → Add**:
- **Name**: `ststor01` (a label)
- **Hostname**: `ststor01` (or its IP)
- **Username**: `natasha`
- Click **Advanced** → check **Use password authentication****Passphrase/Password**: `Bl@kW`
Click **Test Configuration** — should say **Success**. Save.
## Step 4 — Create the job
**New Item** → name `install-packages`**Freestyle project** → OK.
## Step 5 — Add the string parameter
In job config → check **"This project is parameterized"** → **Add Parameter → String Parameter**:
- **Name**: `PACKAGE`
- (default value optional, e.g. `vim-enhanced`)
## Step 6 — Add the build step (install on storage server)
Under **Build Steps****Add build step → Send files or execute commands over SSH**:
- **SSH Server**: select `ststor01`
- **Exec command**:
```bash
sudo yum install -y $PACKAGE
```
Save.
## Step 7 — Build with a parameter
Click **Build with Parameters** → set `PACKAGE` = `vim-enhanced`**Build**.
Check the build's **Console Output** — should show the yum install succeeding.
## Verify
On ststor01:
```bash
rpm -q vim-enhanced # should show it's installed
```
## Task 72
A new DevOps Engineer has joined the team and he will be assigned some Jenkins related tasks. Before that, the team wanted to test a simple parameterized job to understand basic functionality of parameterized builds. He is given a simple parameterized job to build in Jenkins. Please find more details below:
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.
1. Create a parameterized job which should be named as parameterized-job
2. Add a string parameter named Stage; its default value should be Build.
3. Add a choice parameter named env; its choices should be Development, Staging and Production.
4. Configure job to execute a shell command, which should echo both parameter values (you are passing in the job).
5. Build the Jenkins job at least once with choice parameter value Development to make sure it passes.
### solution
# Jenkins job: parameterized-job
## Step 1 — Log in
Click **Jenkins** → login `admin` / `Adm!n321`.
## Step 2 — Create the job
**New Item** → name `parameterized-job`**Freestyle project** → OK.
## Step 3 — Enable parameters
In job config → check **"This project is parameterized"**.
### String parameter
**Add Parameter → String Parameter**:
- **Name**: `Stage`
- **Default Value**: `Build`
### Choice parameter
**Add Parameter → Choice Parameter**:
- **Name**: `env`
- **Choices** (one per line):
```
Development
Staging
Production
```
## Step 4 — Add the shell build step
Under **Build Steps****Add build step → Execute shell**:
```bash
echo "Stage: $Stage"
echo "env: $env"
```
Save.
## Step 5 — Build with parameters
Click **Build with Parameters**:
- `Stage` = `Build` (default)
- `env` = `Development`
Click **Build**.
## Verify
Open the build → **Console Output** → should show:
```
Stage: Build
env: Development
```
Build result: **SUCCESS**.
## Task 73
The devops team of xFusionCorp Industries is working on to setup centralised logging management system to maintain and analyse server logs easily. Since it will take some time to implement, they wanted to gather some server logs on a regular basis. At least one of the app servers is having issues with the Apache server. The team needs Apache logs so that they can identify and troubleshoot the issues easily if they arise. So they decided to create a Jenkins job to collect logs from the server. Please create/configure a Jenkins job as per details mentioned below:
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321
1. Create a Jenkins jobs named copy-logs.
2. Configure it to periodically build every 5 minutes to copy the Apache logs (both access_log and error_log) from App Server 2 (stapp02) from the default logs location to location /usr/src/itadmin on the Storage Server.
3. Build the job at least once so that the logs are copied and can be verified.
### Solution
# Jenkins job: copy-logs
## Step 1 — Log in
Click **Jenkins** → login `admin` / `Adm!n321`.
## Step 2 — Ensure "Publish over SSH" plugin is installed
**Manage Jenkins → Plugins → Available** → search **"SSH"** (Publish Over SSH) → install if not present → restart, wait for login.
## Step 3 — Configure SSH server for App Server 2
**Manage Jenkins → System → Publish over SSH → SSH Servers → Add**:
- **Name**: `stapp02`
- **Hostname**: `stapp02`
- **Username**: `steve`
- **Advanced** → **Use password authentication** → Password: `Am3ric@`
- **Test Configuration** → should succeed. Save.
## Step 4 — Set up passwordless SSH from stapp02 → ststor01
The job will run *on stapp02* and scp to ststor01, so stapp02's steve needs passwordless access to ststor01's natasha. SSH into stapp02 and set it up:
```bash
ssh steve@stapp02
ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa # if not present
ssh-copy-id natasha@ststor01 # password: Bl@kW
# test:
ssh natasha@ststor01 hostname # should return ststor01, no prompt
```
## Step 5 — Create the job
**New Item** → name `copy-logs`**Freestyle project** → OK.
## Step 6 — Configure the schedule (every 5 min)
Check **Build Triggers → Build periodically** → Schedule:
```
*/5 * * * *
```
## Step 7 — Add the build step
**Build Steps → Send files or execute commands over SSH**:
- **SSH Server**: `stapp02`
- **Exec command**:
```bash
scp /var/log/httpd/access_log natasha@ststor01:/usr/src/itadmin/
scp /var/log/httpd/error_log natasha@ststor01:/usr/src/itadmin/
```
Save.
## Step 8 — Build once
Click **Build Now**. Check **Console Output** for success.
## Verify
On ststor01:
```bash
ls -l /usr/src/itadmin/
# should show access_log and error_log
```
## Task 74
There is a requirement to create a Jenkins job to automate the database backup. Below you can find more details to accomplish this task:
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.
Create a Jenkins job named database-backup.
Configure it to take a database dump of the kodekloud_db01 database present on the App server (stapp01) in Stratos Datacenter, the database user is kodekloud_roy and password is asdfgdsd.
The dump should be named in db_$(date +%F).sql format, where date +%F is the current date.
Copy the db_$(date +%F).sql dump to the Storage server (ststor01) under location /home/natasha/db_backups.
Further, schedule this job to run periodically at */10 * * * * (please use this exact schedule format).
### Schedule
# Jenkins job: database-backup
## Step 1 — Log in
Click **Jenkins** → login `admin` / `Adm!n321`.
## Step 2 — Ensure "Publish over SSH" plugin installed
**Manage Jenkins → Plugins → Available** → search **"SSH"** (Publish Over SSH) → install if needed → restart, wait for login.
## Step 3 — Configure SSH server for App Server 1
**Manage Jenkins → System → Publish over SSH → SSH Servers → Add**:
- **Name**: `stapp01`
- **Hostname**: `stapp01`
- **Username**: `tony`
- **Advanced** → **Use password authentication** → Password: `Ir0nM@n`
- **Test Configuration** → success. Save.
## Step 4 — Passwordless SSH from stapp01 → ststor01
The dump runs on stapp01 and scp's to ststor01, so tony@stapp01 needs passwordless access to natasha@ststor01:
```bash
ssh tony@stapp01
ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa # if not present
ssh-copy-id natasha@ststor01 # password: Bl@kW
ssh natasha@ststor01 hostname # test — should return ststor01, no prompt
```
## Step 5 — Create the job
**New Item** → name `database-backup`**Freestyle project** → OK.
## Step 6 — Schedule
**Build Triggers → Build periodically** → Schedule:
```
*/10 * * * *
```
## Step 7 — Build step
**Build Steps → Send files or execute commands over SSH**:
- **SSH Server**: `stapp01`
- **Exec command**:
```bash
mysqldump -u kodekloud_roy -pasdfgdsd kodekloud_db01 > /tmp/db_$(date +%F).sql
scp /tmp/db_$(date +%F).sql natasha@ststor01:/home/natasha/db_backups/
```
Save.
## Step 8 — Build once
Click **Build Now** → check **Console Output** for success.
## Verify
On ststor01:
```bash
ls -l /home/natasha/db_backups/
# should show db_YYYY-MM-DD.sql
```
## Task 75
The Nautilus DevOps team has installed and configured new Jenkins server in Stratos DC which they will use for CI/CD and for some automation tasks. There is a requirement to add all app servers as slave nodes in Jenkins so that they can perform tasks on these servers using Jenkins. Find below more details and accomplish the task accordingly.
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.
1. Add all app servers as SSH build agent/slave nodes in Jenkins. Slave node name for app server 1, app server 2 and app server 3 must be App_server_1, App_server_2, App_server_3 respectively.
2. Add labels as below:
App_server_1 : stapp01
App_server_2 : stapp02
App_server_3 : stapp03
3. Remote root directory for App_server_1 must be /home/tony/jenkins, for App_server_2 must be /home/steve/jenkins and for App_server_3 must be /home/banner/jenkins.
### Solution
# Add app servers as Jenkins SSH build agents
## Step 1 — Log in
Click **Jenkins** → login `admin` / `Adm!n321`.
## Step 2 — Ensure "SSH Build Agents" plugin is installed
**Manage Jenkins → Plugins → Available** → search **"SSH Build Agents"** → install if needed → restart, wait for login.
## Step 3 — Prerequisite: Java + remote dirs on each app server
Agents run a Java process, and the remote root dir must exist. On each app server:
```bash
# App Server 1 (tony)
ssh tony@stapp01
# Ir0nM@n
sudo yum install -y java-17-openjdk # or java-17; match Jenkins controller
mkdir -p /home/tony/jenkins
exit
# App Server 2 (steve)
ssh steve@stapp02
# Am3ric@
sudo yum install -y java-17-openjdk
mkdir -p /home/steve/jenkins
exit
# App Server 3 (banner)
ssh banner@stapp03
# BigGr33n
sudo yum install -y java-21-openjdk
mkdir -p /home/banner/jenkins
exit
```
## Step 4 — Add credentials for each app server
**Manage Jenkins → Credentials → System → Global credentials → Add Credentials**:
For each app server, add a **Username with password** credential:
| Server | Username | Password |
|--------|----------|----------|
| stapp01 | tony | Ir0nM@n |
| stapp02 | steve | Am3ric@ |
| stapp03 | banner | BigGr33n |
(Kind: Username with password. Set a recognizable ID like `stapp01-cred`.)
## Step 5 — Create the three nodes
For **App_server_1**:
**Manage Jenkins → Nodes → New Node**:
- **Node name**: `App_server_1`
- Type: **Permanent Agent** → Create
- **Remote root directory**: `/home/tony/jenkins`
- **Labels**: `stapp01`
- **Usage**: Use this node as much as possible
- **Launch method**: **Launch agents via SSH**
- **Host**: `stapp01`
- **Credentials**: select the tony credential
- **Host Key Verification Strategy**: **Non verifying Verification Strategy** (or Manually trusted)
- Save.
Repeat for **App_server_2**:
- Node name: `App_server_2`
- Remote root directory: `/home/steve/jenkins`
- Labels: `stapp02`
- SSH Host: `stapp02`, credentials: steve
Repeat for **App_server_3**:
- Node name: `App_server_3`
- Remote root directory: `/home/banner/jenkins`
- Labels: `stapp03`
- SSH Host: `stapp03`, credentials: banner
## Step 6 — Verify
**Manage Jenkins → Nodes** — all three (App_server_1/2/3) should show **online** (green, no red X). Click each; the agent log should show a successful connection.
## Task 76
The xFusionCorp Industries has recruited some new developers. There are already some existing jobs on Jenkins and two of these new developers need permissions to access those jobs. The development team has already shared those requirements with the DevOps team, so as per details mentioned below grant required permissions to the developers.
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.
There is an existing Jenkins job named Packages, there are also two existing Jenkins users named sam with password sam@pass12345 and rohan with password rohan@pass12345.
Grant permissions to these users to access Packages job as per details mentioned below:
a.) Make sure to select Inherit permissions from parent ACL under inheritance strategy for granting permissions to these users.
b.) Grant mentioned permissions to sam user : build, configure and read.
c.) Grant mentioned permissions to rohan user : build, cancel, configure, read, update and tag.
Note:
Please do not modify/alter any other existing job configuration.
You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also Jenkins UI sometimes gets stuck when Jenkins service restarts in the back end. In this case, please make sure to refresh the UI page.
For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.
### Solution
# Grant sam + rohan permissions on Packages job
## Step 1 — Log in
Click **Jenkins** → login `admin` / `Adm!n321`.
## Step 2 — Confirm global authorization supports project-based matrix
2. (If Matrix Auth plugin missing) install it → "Restart when complete & no jobs running" → refresh UI if stuck → wait for login page.
3. Ensure global Authorization = Project-based Matrix Auth (don't change if already set; ensure admin keeps Administer).
**Manage Jenkins → Security** → Authorization should be **"Project-based Matrix Authorization Strategy"**. (If it's already set from a prior task, leave it — just ensure admin has Overall/Administer so you don't lock out.)
## Step 3 — Open the Packages job's security config
Go to the **Packages** job → **Configure** → find **"Enable project-based security"** and check it.
Set **Inheritance Strategy****"Inherit permissions from parent ACL"**.
## Step 4 — Add sam and grant permissions
Click **Add user** → enter `sam` → check these boxes for sam:
- **Job → Build**
- **Job → Configure**
- **Job → Read**
## Step 5 — Add rohan and grant permissions
Click **Add user** → enter `rohan` → check these for rohan:
- **Job → Build**
- **Job → Cancel** (under Run category, "Cancel")
- **Job → Configure**
- **Job → Read**
- **Job → Update** (SCM/Update — the "Update" permission)
- **Job → Tag** (SCM → Tag)
## Step 6 — Save
Click **Save**.
## Verify
- Log in as `sam` → can see/build/configure Packages, nothing more.
- Log in as `rohan` → can see/build/cancel/configure/update/tag Packages.
## Task 77
The development team of xFusionCorp Industries is working on to develop a new static website and they are planning to deploy the same on Nautilus App Server using Jenkins pipeline. They have shared their requirements with the DevOps team and accordingly we need to create a Jenkins pipeline job. Please find below more details about the task:
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.
Similarly, click on the Gitea button on the top bar to access the Gitea UI. Login using username sarah and password Sarah_pass123. There under user sarah you will find a repository named web_app that is already cloned on App Server 1 under /var/www/html. sarah is a developer who is working on this repository.
Add a slave node named App Server 1. It should be labeled as stapp01 and its remote root directory should be /home/sarah/jenkins_agent (the repository is cloned under /var/www/html; the agent uses a separate directory so it does not pollute the repo).
We have already cloned repository on App Server 1 under /var/www/html.
Apache is already installed on the app server and is running on port 8080.
Create a Jenkins pipeline job named xfusion-webapp-job (it must not be a Multibranch pipeline) and configure it to:
Deploy the code from web_app repository under /var/www/html on App Server 1, as this is the document root of the app server. The pipeline should have a single stage named Deploy ( which is case sensitive ) to accomplish the deployment.
LB server is already configured. You should be able to see the latest changes you made by clicking on the App button. Please make sure the required content is loading on the main URL https://<LBR-URL> i.e there should not be a sub-directory like https://<LBR-URL>/web_app etc.
Note:
You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also, Jenkins UI sometimes gets stuck when Jenkins service restarts in the back end. In this case, please make sure to refresh the UI page.
For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.
### Solution
#### Prerequisities
```bash
ssh sarah@stapp01 # or via the appropriate user
# Sarah_pass123
# Java for the agent (match controller — likely 17)
sudo yum install -y java-17-openjdk
sudo alternatives --set java java-17-openjdk.x86_64 # make it default
java -version
# agent working dir
mkdir -p /home/sarah/jenkins_agent
# confirm the repo is there + git works in docroot
cd /var/www/html
sudo git status # confirm it's a git clone of web_app
```
# Jenkins pipeline: xfusion-webapp-job
## Step 1 — Log in
Jenkins UI → `admin` / `Adm!n321`.
## Step 2 — Install required plugins
Likely needed: **SSH Build Agents**, **Pipeline**, **Git**.
**Manage Jenkins → Plugins → Available** → install any missing → **"Restart Jenkins when installation is complete and no jobs are running"** → refresh UI if it hangs → wait for login page.
## Step 3 — Add credentials for sarah@stapp01
**Manage Jenkins → Credentials → Global → Add Credentials**:
- Kind: Username with password
- Username: `sarah`
- Password: (sarah's app-server password — check the creds table)
- ID: `stapp01-sarah`
## Step 4 — Add the agent node
**Manage Jenkins → Nodes → New Node**:
- **Name**: `App Server 1` (exact — with spaces)
- Type: Permanent Agent
- **Remote root directory**: `/home/sarah/jenkins_agent`
- **Labels**: `stapp01`
- **Launch method**: Launch agents via SSH
- Host: `stapp01`
- Credentials: `stapp01-sarah`
- Host Key Verification Strategy: **Non verifying**
- Save → confirm it comes **online**.
## Step 5 — Create the pipeline job
**New Item** → name `xfusion-webapp-job`**Pipeline** (NOT Multibranch) → OK.
In the job config → **Pipeline** section → Definition: **Pipeline script** → paste:
```groovy
pipeline {
agent { label 'stapp01' }
stages {
stage('Deploy') {
steps {
sh '''
cd /var/www/html
git pull origin master
'''
}
}
}
}
```
Save.
## Step 6 — Build
**Build Now** → check Console Output for success.
## Step 7 — Verify
- App button / `https://<LBR-URL>` shows the web_app content at the **root** (no /web_app subdir).
- On stapp01: `ls /var/www/html` shows the latest repo files.
## Task 78
The development team of xFusionCorp Industries is working on to develop a new static website and they are planning to deploy the same on Nautilus App Server using Jenkins pipeline. They have shared their requirements with the DevOps team and accordingly we need to create a Jenkins pipeline job. Please find below more details about the task:
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and password Adm!n321.
Similarly, click on the Gitea button on the top bar to access the Gitea UI. Login using username sarah and password Sarah_pass123. There under user sarah you will find a repository named web_app that is already cloned on App Server 1 under /var/www/html. sarah is a developer who is working on this repository.
Add a slave node named App Server 1. It should be labeled as stapp01 and its remote root directory should be /home/sarah/jenkins_agent (the repository is cloned under /var/www/html).
We have already cloned repository on App Server 1 under /var/www/html.
Apache is already installed on the app server and is running on port 8080.
Create a Jenkins pipeline job named nautilus-webapp-job (it must not be a Multibranch pipeline) and configure it to:
Add a string parameter named BRANCH.
It should conditionally deploy the code from web_app repository under /var/www/html on App Server 1, as this is the document root of the app server. The pipeline should have a single stage named Deploy ( which is case sensitive ) to accomplish the deployment.
The pipeline should be conditional, if the value master is passed to the BRANCH parameter then it must deploy the master branch, on the other hand if the value feature is passed to the BRANCH parameter then it must deploy the feature branch.
LB server is already configured. You should be able to see the latest changes you made by clicking on the App button. Please make sure the required content is loading on the main URL https://<LBR-URL> i.e there should not be a sub-directory like https://<LBR-URL>/web_app etc.
Note:
You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also, Jenkins UI sometimes gets stuck when Jenkins service restarts in the back end. In this case, please make sure to refresh the UI page.
For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.
### Solution
#### Prerequisities
```bash
ssh sarah@stapp01 # or via the appropriate user
# Sarah_pass123
# Java for the agent (match controller — likely 17)
sudo yum install -y java-17-openjdk
sudo alternatives --set java java-17-openjdk.x86_64 # make it default
java -version
# agent working dir
mkdir -p /home/sarah/jenkins_agent
# confirm the repo is there + git works in docroot
cd /var/www/html
sudo git status # confirm it's a git clone of web_app
```
## Step 2 — Install required plugins
Likely needed: **SSH Build Agents**, **Pipeline**, **Git**.
**Manage Jenkins → Plugins → Available** → install any missing → **"Restart Jenkins when installation is complete and no jobs are running"** → refresh UI if it hangs → wait for login page.
## Step 3 — Add credentials for sarah@stapp01
**Manage Jenkins → Credentials → Global → Add Credentials**:
- Kind: Username with password
- Username: `sarah`
- Password: (sarah's app-server password — check the creds table)
- ID: `stapp01-sarah`
## Step 4 — Add the agent node
**Manage Jenkins → Nodes → New Node**:
- **Name**: `App Server 1` (exact — with spaces)
- Type: Permanent Agent
- **Remote root directory**: `/home/sarah/jenkins_agent`
- **Labels**: `stapp01`
- **Launch method**: Launch agents via SSH
- Host: `stapp01`
- Credentials: `stapp01-sarah`
- Host Key Verification Strategy: **Non verifying**
- Save → confirm it comes **online**.
# Jenkins pipeline: nautilus-webapp-job (conditional)
## Create the pipeline job
**New Item** → name `nautilus-webapp-job`**Pipeline** (NOT Multibranch) → OK.
## Add the string parameter
Check **"This project is parameterized"** → **Add Parameter → String Parameter**:
- **Name**: `BRANCH`
## Pipeline script
**Pipeline** section → Definition: **Pipeline script** → paste:
```groovy
pipeline {
agent { label 'stapp01' }
stages {
stage('Deploy') {
steps {
script {
if (params.BRANCH == 'master') {
sh '''
cd /var/www/html
git checkout master
git pull origin master
'''
} else if (params.BRANCH == 'feature') {
sh '''
cd /var/www/html
git checkout feature
git pull origin feature
'''
}
}
}
}
}
}
```
Save.
## Build
**Build with Parameters** → set `BRANCH` = `master` (then test again with `feature`) → Build.
## Verify
- App button / `https://<LBR-URL>` shows the deployed branch's content at root.
- On stapp01: `cd /var/www/html && git branch` shows the checked-out branch.
## Task 79
The Nautilus development team had a meeting with the DevOps team where they discussed automating the deployment of one of their apps using Jenkins (the one in Stratos Datacenter). They want to auto deploy the new changes in case any developer pushes to the repository. As per the requirements mentioned below configure the required Jenkins job.
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and Adm!n321 password.
Similarly, you can access the Gitea UI using Gitea button. Username and password for Git are sarah and Sarah_pass123. Under user sarah you will find a repository named web that is already cloned on App Server 1 under sarah's home (/home/sarah/web). sarah is a developer who is working on this repository.
1. httpd is already installed and configured on the app server (listening on port 8080). Ensure the httpd service is running on App Server 1 (e.g. start it manually if needed). You can make starting/restarting httpd part of your Jenkins job if you prefer.
2. Create a Jenkins job named datacenter-app-deployment and configure it so that if anyone pushes any new change to the origin repository in master branch, the job should auto build and deploy the latest code on App Server 1 under /var/www/html directory.
Before deployment, ensure that the ownership of the /var/www/html directory is set to user sarah, so that Jenkins can successfully deploy files to that directory.
3. SSH into App Server 1 using sarah user credentials mentioned above. Under sarah user's home (/home/sarah/web) you will find a cloned Git repository named web. Under this repository there is an index.html file, update its content to Welcome to the xFusionCorp Industries, then push the changes to the origin into master branch. This push must trigger your Jenkins job and the latest changes must be deployed on the server, also make sure it deploys the entire repository content not only index.html file.
Click on the App button on the top bar to access the app. Please make sure the required content is loading on the main URL (e.g. http://stlb01:8091) i.e there should not be any sub-directory like http://stlb01:8091/web etc.
Note:
1. You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also some times Jenkins UI gets stuck when Jenkins service restarts in the back end so in such case please make sure to refresh the UI page.
2. Make sure Jenkins job passes even on repetitive runs as validation may try to build the job multiple times.
3. Deployment related tasks should be done by sudo user on the destination server to avoid any permission issues so make sure to configure your Jenkins job accordingly.
4. For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.
### Solution
#### Prerequisities
```bash
ssh sarah@stapp01 # or via the appropriate user
# Sarah_pass123
# Java for the agent (match controller — likely 17)
sudo yum install -y java-17-openjdk
sudo alternatives --set java java-17-openjdk.x86_64 # make it default
java -version
# agent working dir
mkdir -p /home/sarah/jenkins_agent
# confirm the repo clone
cd /home/sarah/web && git remote -v && git branch
```
# Jenkins job: datacenter-app-deployment (webhook auto-deploy)
## Step 1 — Plugins
Ensure installed: **Git**, **Gitea** (or Generic Webhook Trigger), **Publish Over SSH** or the agent approach.
Install missing → restart → refresh UI if stuck.
## Step 2 — Node or SSH config for stapp01
Either use an SSH agent node (label stapp01) OR Publish-Over-SSH to stapp01.
(Given note #3 "use sudo on destination," the job runs commands on stapp01 as sarah with sudo.)
## Step 3 — Create the job
**New Item** → `datacenter-app-deployment`**Freestyle project** → OK.
## Step 4 — Source Code Management
**Git**:
- Repository URL: the Gitea `web` repo URL (e.g. `http://<gitea>/sarah/web.git`)
- Credentials: sarah / Sarah_pass123
- Branch: `*/master`
## Step 5 — Build Trigger
Check **"Poll SCM"** as a fallback AND configure the Gitea webhook trigger:
- If Gitea plugin: check **"Build when a change is pushed to Gitea"**
- (Fallback: Poll SCM with `* * * * *` or a webhook)
## Step 6 — Build step
**Execute shell** (if job runs on stapp01 agent) — deploy the repo contents to docroot:
```bash
sudo cp -r $WORKSPACE/* /var/www/html/
sudo systemctl restart httpd
```
Or if pulling directly on the server, sync the /home/sarah/web content.
## Step 7 — Configure Gitea webhook
In Gitea → repo `web`**Settings → Webhooks → Add Webhook → Gitea**:
- Target URL: `http://<jenkins-url>/gitea-webhook/post` (or the Jenkins job's webhook endpoint)
- Trigger: Push events
- Save → Test Delivery.
## Step 8 — Make the change + push (proves the trigger)
On stapp01 as sarah:
```bash
cd /home/sarah/web
echo "Welcome to the xFusionCorp Industries" > index.html
git add index.html
git commit -m "Update index.html"
git push origin master
```
This push should auto-trigger the Jenkins job.
## Verify
- Jenkins job auto-built after the push.
- `http://stlb01:8091` shows "Welcome to the xFusionCorp Industries" at root.
- `/var/www/html` contains the full repo content, not just index.html.
## Tak 80
The DevOps team was looking for a solution where they want to restart Apache service on all app servers if the deployment goes fine on these servers in Stratos Datacenter. After having a discussion, they came up with a solution to use Jenkins chained builds so that they can use a downstream job for services which should only be triggered by the deployment job. So as per the requirements mentioned below configure the required Jenkins jobs.
Click on the Jenkins button on the top bar to access the Jenkins UI. Login using username admin and Adm!n321 password.
Similarly you can access Gitea UI on port 3000 (or click the Gitea button) and username and password for Git is sarah and Sarah_pass123 respectively. Under user sarah you will find a repository named web.
Apache is already installed and configured on the app server. The doc root /var/www/html on App Server 1 is a local git repository tracking the origin web repository.
1. Create a Jenkins job named devops-app-deployment and configure it to pull changes from the master branch of the web repository on App Server 1 under /var/www/html directory.
2. Create another Jenkins job named manage-services and make it a downstream job for devops-app-deployment. Things to take care about this job are:
a. This job should restart httpd service on the app server (App Server 1).
b. Trigger this job only if the upstream job i.e devops-app-deployment is stable.
The LB server is already configured. Click on the App button on the top bar to access the app. Please make sure the required content is loading on the main URL (e.g. http://stlb01:8091) i.e there should not be a sub-directory like http://stlb01:8091/web etc.
Note:
1. You might need to install some plugins and restart Jenkins service. So, we recommend clicking on Restart Jenkins when installation is complete and no jobs are running on plugin installation/update page i.e update centre. Also some times Jenkins UI gets stuck when Jenkins service restarts in the back end so in such case please make sure to refresh the UI page.
2. Make sure Jenkins job passes even on repetitive runs as validation may try to build the job multiple times.
3. Deployment related tasks should be done by sudo user on the destination server to avoid any permission issues so make sure to configure your Jenkins job accordingly.
4. For these kind of scenarios requiring changes to be done in a web UI, please take screenshots so that you can share it with us for review in case your task is marked incomplete. You may also consider using a screen recording software such as loom.com to record and share your work.
### Solution
# Chained Jenkins Builds: devops-app-deployment → manage-services
### Complete setup from an empty Jenkins
---
## PART 0 — Prerequisites on App Server 1 (CLI)
SSH into stapp01 and set up NOPASSWD sudo for sarah (deploy commands need passwordless sudo).
```bash
ssh sarah@stapp01
# password: Sarah_pass123
# NOPASSWD sudo drop-in
echo 'sarah ALL=(ALL) NOPASSWD: ALL' | sudo tee /etc/sudoers.d/sarah
sudo chmod 0440 /etc/sudoers.d/sarah
sudo visudo -c # must say "parsed OK"
sudo -n true && echo "NOPASSWD works" # must print NOPASSWD works
# confirm docroot is a git repo tracking origin web
cd /var/www/html
sudo git remote -v # should show the 'web' origin
sudo git branch # note the branch (master)
# ensure httpd is running
sudo systemctl start httpd
sudo systemctl status httpd --no-pager
exit
```
---
## PART 1 — Install required plugins
Jenkins UI → login `admin` / `Adm!n321`.
**Manage Jenkins → Plugins → Available plugins**, search and install:
- **Publish Over SSH**
Check **"Restart Jenkins when installation is complete and no jobs are running"**.
Wait for the restart; if the UI hangs, **refresh the page**. Wait for the login page, then log back in.
---
## PART 2 — Configure the SSH server (stapp01)
**Manage Jenkins → System** (Configure System) → scroll to **Publish over SSH****SSH Servers → Add**:
| Field | Value |
|-------|-------|
| Name | `stapp01` |
| Hostname | `stapp01` |
| Username | `sarah` |
Click **Advanced** → check **Use password authentication, or use a different key**:
| Field | Value |
|-------|-------|
| Passphrase / Password | `Sarah_pass123` |
Click **Test Configuration** → must return **Success**. **Save**.
---
## PART 3 — Job 1: devops-app-deployment (the deploy)
**New Item** → name `devops-app-deployment`**Freestyle project** → OK.
### Build step
**Build Steps → Add build step → Send files or execute commands over SSH**:
- **SSH Server**: `stapp01`
- **Exec command**:
```bash
cd /var/www/html
sudo git checkout master
sudo git pull origin master
```
**Save.**
---
## PART 4 — Job 2: manage-services (downstream service restart)
**New Item** → name `manage-services`**Freestyle project** → OK.
### Build step
**Build Steps → Add build step → Send files or execute commands over SSH**:
- **SSH Server**: `stapp01`
- **Exec command**:
```bash
sudo systemctl restart httpd
```
**Save.**
---
## PART 5 — Chain the jobs (upstream → downstream, only if stable)
Open **devops-app-deployment → Configure**:
**Post-build Actions → Add post-build action → Build other projects**:
- **Projects to build**: `manage-services`
- Select **"Trigger only if build is stable"**
**Save.**
---
## PART 6 — Run and verify
### Build the upstream job
Open **devops-app-deployment → Build Now**.
### Check the chain
- `devops-app-deployment` completes **stable** (blue/green ball, SUCCESS).
- It automatically triggers **manage-services** (visible in the build's "Downstream" section / console).
- `manage-services` runs and restarts httpd.
### Verify on the servers
```bash
# on stapp01
ssh sarah@stapp01 'cd /var/www/html && git log --oneline -3' # latest master pulled
ssh sarah@stapp01 'systemctl is-active httpd' # active
```
### Verify the app
Click the **App** button → `http://stlb01:8091` must show the site content at the **root** (no `/web` subdirectory).
---
## Key points
- **Chaining is set on the UPSTREAM job** — "Build other projects" post-build action in `devops-app-deployment`, pointing at `manage-services`.
- **"Trigger only if build is stable"** — `manage-services` runs ONLY when the deploy job is SUCCESS. Failed/unstable deploy → no httpd restart. This is the core requirement (restart Apache only if deployment goes fine).
- **Docroot is the git repo** — `/var/www/html` tracks origin `web`, so the deploy is an in-place `sudo git pull origin master`. Files sit at docroot root → served at `/` → no `/web` subdirectory.
- **Both jobs reach stapp01 via Publish Over SSH** — commands in the "Exec command" boxes run ON stapp01 as sarah. NOPASSWD sudo makes `sudo git` / `sudo systemctl` non-interactive.
- **Idempotent (repeatable)** — `git checkout master` (no-op if already there), `git pull` ("already up to date"), `systemctl restart` (repeatable). Repeated builds of either job pass — important since validation builds multiple times.
- **Separate jobs by design** — httpd restart lives in its own downstream job, not baked into the deploy. That separation IS the "chained builds" architecture the task asks for.
---
## Screenshots to capture (for review)
- `devops-app-deployment` config showing the SSH exec step + the post-build "Build other projects → manage-services (only if stable)".
- `manage-services` config showing the httpd restart step.
- A successful build of `devops-app-deployment` showing it triggered `manage-services`.
- The app loading at the root URL.