In this tutorial, we will guide you through the process of building a CI/CD pipeline with Jenkins on Ubuntu, empowering you to automate your software delivery process and streamline your development workflow. In today’s fast-paced software development world, Continuous Integration and Continuous Delivery (CI/CD) have become crucial practices for ensuring the efficiency and quality of software releases. Jenkins, a popular open-source automation server, is widely used for setting up CI/CD pipelines.
Section 1: Installing Jenkins on Ubuntu
To begin, we need to install Jenkins on Ubuntu machine. Open a terminal and execute the following commands:
# sudo apt update
# sudo apt install fontconfig openjdk-11-jre -y
# curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
# 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
# sudo apt install ca-certificates
# sudo apt update
# sudo apt install jenkins -y
These commands will update the package list, install Java Development Kit (JDK), add the Jenkins repository key, add the Jenkins repository to your sources, update the package list again, and finally, install Jenkins on Ubuntu machine.
Section 2: Starting Jenkins
Once Jenkins on Ubuntu is installed, we need to start its service. Execute the following commands:
sudo systemctl start jenkins
sudo systemctl enable jenkins
These commands will start Jenkins on Ubuntu service and configure it to start automatically on system boot.
Section 3: Accessing Jenkins
To access the Jenkins web interface, open a web browser and enter http://localhost:8080
or http://<your-server-IP>:8080
if you are accessing Jenkins remotely. You will be prompted to enter an initial administrator password.
Retrieve the password by executing the following command in the terminal:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and paste it into the Jenkins web interface to proceed with the setup.
Section 4: Configuring Jenkins
Once you have entered the initial administrator password, Jenkins will guide you through the setup wizard. Follow the on-screen instructions to install suggested plugins or choose specific plugins that suit your requirements.
After plugin installation, create an admin user and provide the necessary details.
Section 5: Creating a Jenkins Job
Now, let’s create a Jenkins job to define our CI/CD pipeline. Follow these steps:
- Click on “Create new jobs” on the Jenkins dashboard.
- Provide a name for your job and select the “Freestyle project” option.
- Click “OK” to proceed.
- In the configuration page, under the “Source Code Management” section, choose your preferred version control system (e.g., Git).
- Specify the repository URL and credentials, if required.
- Under the “Build Triggers” section, choose the appropriate trigger options (e.g., Poll SCM or webhook).
- In the “Build” section, define the build steps according to your project’s requirements. For example, you can add commands to compile the code, run tests, or package the application.
- Save the configuration.
Section 6: Extending the Pipeline for CD
To extend the pipeline for Continuous Delivery, we need to add deployment steps. Follow these steps:
- Go to your Jenkins job configuration page.
- Under the “Post-build Actions” section, click “Add post-build action.”
- Choose the appropriate deployment action based on your deployment strategy (e.g., SSH, FTP, or containerization).
- Configure the deployment parameters such as the target server, credentials, and destination directory.
- Save the configuration.
Section 7: Running the Pipeline
To run the CI/CD pipeline, follow these steps:
- Go to the Jenkins dashboard.
- Locate your Jenkins job and click on it.
- Click on the “Build Now” button to trigger a manual build.
- Jenkins will execute the defined build steps, run tests, and deploy the application (if configured).
- Monitor the build console output for any errors or issues.
Final thoughts
Congratulations! You have successfully built a CI/CD pipeline with Jenkins on Ubuntu using the provided Linux commands. By automating your software delivery process, you can improve productivity and ensure high-quality releases. Continue exploring Jenkins and its vast ecosystem of plugins to further enhance your CI/CD pipeline and optimize your development workflow.
0 Comments