lab5

 2. Installing Jenkins on a Local Machine (Ubuntu)

Below are detailed step-by-step instructions for installing Jenkins on an Ubuntu machine.

Step 1: Update Your System

Open your terminal and update your system repositories:

sudo apt update sudo

apt upgrade -y

Step 2: Install Java

Jenkins requires Java to run. It is recommended to use Java 11 or later. Install OpenJDK 11:

sudo apt install openjdk-11-jdk -y java

version

Expected Output Example:

openjdk version "11.0.11" 2021-04-20

Step 3: Add the Jenkins Repository Key

Download and add the repository key so that your system trusts the Jenkins packages:

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt- key add -

Step 4: Add the Jenkins Repository

Add the Jenkins repository to your system’s sources list:

sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ >

/etc/apt/sources.list.d/jenkins.list'

Step 5: Update the Repository and Install Jenkins

Update the package list and install Jenkins:

sudo apt update

sudo apt install jenkins -y

Step 6: Start and Enable the Jenkins Service

Start Jenkins and configure it to start automatically on boot:

sudo systemctl start jenkins sudo

systemctl status jenkins

• What it does:

o start jenkins launches the Jenkins service.

o status jenkins confirms Jenkins is running.

• Expected Output: A status message indicating Jenkins is active (running).

Step 7: Access Jenkins on the Local Machine

1. Open a

Navigate to:

Web Browser:

2. http://localhost:8080

3. Unlock

Jenkins:

The initial Jenkins screen will ask for an administrator password. Retrieve it by

running:

4. sudo cat /var/lib/jenkins/secrets/initialAdminPassword

o What it does: Displays the auto-generated admin password.

o Screenshot Tip: Capture the terminal output showing the password and the

Jenkins unlock screen.

5. Follow the Setup Wizard:

o Install Suggested Plugins: Click on “Install suggested plugins” for a typical

setup.

o Create an Admin User: Follow prompts to create your first admin user.

o Finalize Configuration: Complete the remaining setup steps (e.g., instance

configuration).

o Screenshot Tip: Capture each major step (unlocking Jenkins, plugin installation,

and admin user creation).

3. Installing Jenkins on the Cloud (Optional)

There are several ways to run Jenkins on the cloud. One common method is to run Jenkins

using a Docker container on a cloud virtual machine. Below are instructions using Docker on

an Ubuntu cloud server (for example, on AWS EC2, DigitalOcean, or any cloud provider that

supports Ubuntu).

Step 1: Set Up a Cloud VM Running Ubuntu

1. Provision a New Ubuntu Server:

o Create a new VM using your cloud provider’s console.

o Ensure the VM has at least 1–2 GB RAM.

o Open port 8080 (and port 50000 for agent communication) in the security group

settings.

o Connect to the VM via SSH:

o ssh your-username@your-cloud-server-ip

Step 2: Install Docker on Your Cloud VM

1. Update the System:

2. sudo apt update

3. sudo apt upgrade -y

4. Install Docker:

5. sudo apt install docker.io -y

6. sudo systemctl start docker

7. sudo systemctl enable docker

8. Verify Docker Installation:

9. docker --version

Step 3: Run Jenkins in a Docker Container

1. Pull the Official Jenkins Image:

2. sudo docker pull jenkins/jenkins:lts

3. Run the Jenkins Container:

4. sudo docker run -d --name jenkins -p 8080:8080 -p 50000:50000 -v

jenkins_home:/var/jenkins_home jenkins/jenkins:lts

o What it does:

▪ -d runs the container in detached mode.

▪ --name jenkins names the container.

▪ -p 8080:8080 maps port 8080 (Jenkins UI) to the host.

▪ -p 50000:50000 maps the agent communication port.

▪ -v jenkins_home:/var/jenkins_home mounts a persistent volume for

Jenkins data.

o sudo docker ps

5. Access Jenkins on the Cloud VM:

o Open your browser and navigate to:

o http://your-cloud-server-ip:8080

o Follow the same unlocking and setup wizard process as described in the local

installation steps.

4. Configuring Jenkins for First Use

After installing Jenkins (locally or on the cloud), complete these steps to configure it for first

use:

Step 1: Unlock Jenkins

• Retrieve

the

Admin Password:

As described earlier, run:

• sudo cat /var/lib/jenkins/secrets/initialAdminPassword

• Enter

the

Password:

Copy the password into the “Administrator Password” field on the Jenkins unlock page.

Step 2: Install Suggested Plugins

• Click “Install

suggested

plugins”: This option installs a set of commonly

used plugins (e.g., Git, Maven Integration, Pipeline).

• Wait for Installation:

The plugin installation process might take several minutes.

Step 3: Create Your First Admin User

• Enter

the

Admin User Details:

Provide a username, password, full name, and email address.

• Confirm

Creation:

Click “Save and Continue” once the details are entered.

Step 4: Configure the Instance

• Instance

Configuration:

Jenkins may ask you to confirm the URL for your Jenkins instance. Verify that it is

correct (e.g., http://localhost:8080 for local installations or your cloud server’s IP

address for cloud installations).

• Save the Configuration:

Confirm the settings and proceed.

Step 5: Start Using Jenkins

• Dashboard:

Once the setup is complete, you will be taken to the Jenkins dashboard where you can:

o Create new jobs (Freestyle projects, Pipelines, etc.)

o Install additional plugins as needed.

o Monitor builds and view logs.

Comments

Popular posts from this blog

lab2

lab1

lab4