Skip to main content

Command Palette

Search for a command to run...

#Day 22 - Getting started with Jenkins

Published
4 min read
#Day 22 - Getting started with Jenkins
A

Passionate AWS Developer | DevOps Engineer with a strong background in cloud architecture and solutions engineering. Leveraging the power of Amazon Web Services (AWS), knowledge of the AWS global infrastructure, design and implement robust cloud-based solutions that align with clients' specific needs.

What is Jenkins?

Jenkins is an open-source automation server that is widely used for building, deploying, and automating software projects. It provides a platform for continuous integration and continuous delivery (CI/CD), which are practices in software development that aim to improve the development and release process by automating various stages.

Here are some key features and functions of Jenkins:

  1. Continuous Integration (CI): Jenkins can automatically build, test, and integrate code changes from multiple contributors into a shared repository. This helps identify and address integration issues early in the development process.

  2. Continuous Delivery (CD): Jenkins can automate the deployment of software to various environments, such as development, testing, staging, and production. This streamlines the release process and ensures that software changes can be easily and reliably delivered to end-users.

  3. Extensibility: Jenkins is highly extensible and supports a wide range of plugins that allow you to integrate it with various tools and technologies, such as version control systems (e.g., Git), build tools, testing frameworks, and deployment platforms.

  4. Distributed Builds: Jenkins can distribute build and test tasks across multiple machines or agents, which helps improve scalability and performance.

  5. Monitoring and Reporting: Jenkins provides detailed logs and reports on the status of builds and deployments, making it easier to track the progress and quality of software development projects.

  6. Security: Jenkins offers various security features, including user authentication, authorization, and role-based access control, to ensure that access to the system is properly controlled.

  7. Workflow Support: Jenkins supports the creation of complex build and deployment pipelines using tools like Jenkins Pipeline, which allows you to define the entire workflow as code.

  8. Community and Support: Jenkins has a large and active user community, and there is a wealth of documentation and online resources available for users to learn, troubleshoot, and get help.

Jenkins is a popular choice in the DevOps community because of its flexibility and extensibility, allowing teams to tailor their CI/CD pipelines to their specific needs and integrate them with a wide range of development and deployment tools.

Installing and setting up Jenkins:

Pre-requisites:

Minimum hardware requirements:

  • 256 MB of RAM

  • 1 GB of drive space (although 10 GB is a recommended minimum if running Jenkins as a Docker container)

Jenkins requires Java 11 or 17 since Jenkins 2.357 and LTS 2.361.1.

Installing Jenkins:

First of all Install Java on your system because Jenkins is written in Java.

  sudo apt-get update
  sudo apt install openjdk-11-jdk

To check the version installed, use the following command:

java -version

Install Jenkins.

Download the Jenkins repository key and save it in a file using sudo.

   curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
    /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Add the Jenkins repository as a package for the package manager (apt) on your Ubuntu.

  echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
    https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
    /etc/apt/sources.list.d/jenkins.list > /dev/null

Update your system, again.

  sudo apt-get update

Install Jenkins:

  sudo apt-get install jenkins

Jenkins is installed, we can check the version of jenkins.

Configure Jenkins:

Go to EC2 console, modify the security group for Inbound rules. Open port 8080 to your host from CustomTCP.

Verify Jenkins configuration by opening it in your browser ec2_ip:8080

Open your hostIP:8080 in your browser. You should get the “Getting Started” page.

Use the directory and your host using the following command to get the administrator password. copy and paste the admin password in page.

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

Click on Install suggested plugins and Wait for the installation of plugins to complete. It usually takes 4–8 minutes.

Once the installation is complete, the “Create First Admin User” page appears. Provide the details and go ahead by clicking on Save and Continue.

Congratulations! You have successfully installed Jenkins on your host and connected to the Jenkins web server.

Task:

Create a freestyle pipeline to print "Hello World".

Click on “New Item” to create a new Jenkins job.

Enter the name for the job “HelloWorldPipeline” and select “Freestyle project”, then click “OK”.

In the configuration page that appears, scroll down to the “Build” section. Click on the “Add build step” dropdown and select “Execute shell” as the host machine’s OS is Linux.

Once you select Execute shell, the Execute shell window opens. In the command section, enter the following:

echo "hello World"

Click on Save, after entering the command to save the pipeline configuration.

Run the pipeline, to see the output in the console log. To run the pipeline, go to your Pipeline dashboard and click on Build Now.

Click on #1 Build to view the build and go to console output to view the output.

We can see that Build is successfull, and we have created a freestyle pipeline to print "Hello World".