Skip to content

Continuous Integration and Continuous Deployment (CI/CD) with Jenkins ⚙

Jenkins is a widely used open-source automation server that supports building, deploying, and automating projects. It is known for its extensibility through plugins and is a popular choice for CI/CD pipelines.

Components of Jenkins:

  • Jobs 🛠️
  • Builds 🚀
  • Plugins 🧩
  • Nodes 🖥️
  • Artifacts 📂

Real-Time Use Case:

Jenkins is versatile and can be used for various scenarios, from building and testing code to deploying applications. It's an excellent choice for organizations with diverse automation needs.

Mostly Used For:

  • Continuous Integration (CI)
  • Continuous Deployment (CD)
  • Automated Testing
  • Scheduled Jobs and Tasks

Installation Process:

  1. Download and install Jenkins on your server or machine.
  2. Access the Jenkins web interface in your browser.
  3. Install necessary plugins to extend Jenkins' functionality.
  4. Create Jenkins jobs or pipelines to define your CI/CD processes.
  5. Configure job triggers, source code management, and build steps.
  6. Save and run your Jenkins jobs.

Understanding Jenkins Artifacts and Its Use Cases

What are Jenkins Artifacts

Jenkins Artifacts are files or outputs generated during the build and deployment processes. These artifacts can include compiled binaries, reports, logs, or any other files produced by Jenkins jobs. They are essential for tracking and sharing build results.

Pipeline Artifacts vs Jenkins Artifacts: Differences and Best Practices

When working with Jenkins, it's essential to understand the difference between Pipeline Artifacts and Jenkins Artifacts and when to use each effectively.

Pipeline Artifacts

Pipeline Artifacts refer to files generated during the execution of a Jenkins pipeline. They can include build artifacts, test results, and any other files produced as part of the pipeline's workflow. Pipeline Artifacts are often temporary and used for a specific job or task.

Jenkins Artifacts

Jenkins Artifacts, on the other hand, encompass a broader range of files and outputs generated by Jenkins jobs, not just limited to pipelines. They can include build artifacts, archived logs, test reports, and more. Jenkins Artifacts are typically stored for historical reference and can be accessed across different jobs and builds.

When to Use Each

  • Pipeline Artifacts: Utilize Pipeline Artifacts when you need to store and manage files generated during the execution of a specific Jenkins pipeline. These artifacts are often temporary and are useful for debugging or further processing within the same pipeline.

  • Jenkins Artifacts: Opt for Jenkins Artifacts when you want to retain a broader set of files and outputs generated by Jenkins jobs, not limited to pipelines. These artifacts serve as a historical record and can be accessed and shared across different jobs and builds.

Creating and Managing Pipelines in Jenkins 👷

Jenkins provides robust support for creating and managing pipelines. You can define pipelines using the built-in pipeline DSL, scripted pipelines, or declarative pipelines.

Freestyle Projects

Freestyle Projects offer a graphical interface for creating Jenkins jobs and pipelines. They are suitable for simple automation tasks and require minimal scripting.

Creating 1st Basic Pipeline to Run Hello World:

  1. Open Jenkins and navigate to the "New Item" menu.
  2. Select "Pipeline" and provide a name for your project.
  3. Configure the pipeline using a Jenkinsfile or the visual editor.
  4. Define stages, steps, and agent configurations.
  5. Save your pipeline configuration.
  6. Trigger your pipeline manually or by code commits.

Declarative Pipelines

Declarative Pipelines provide a structured way to define pipelines using a simplified, human-readable syntax. They are a good choice for straightforward CI/CD workflows.

Creating a "Hello, World!" Declarative Pipeline using Groovy 🚀

  1. In your Jenkins dashboard, click on "New Item" to create a new project.
  2. Enter a name for your project, select "Pipeline," and click "OK."
  3. In the pipeline configuration, scroll down to the "Pipeline" section.
  4. Select "Pipeline script" from the "Definition" dropdown.
  5. In the "Pipeline script" box, enter the following Groovy script to print "Hello, World!":
    pipeline {
        agent any
        stages {
            stage('Hello') {
                steps {
                    echo 'Hello, World!'
                }
            }
        }
    }
    
  6. Save your project configuration.

Now, when you build this project, it will execute the "Hello, World!" script defined in the Groovy pipeline.

Scripted Pipelines

  • Scripted Pipelines offer full flexibility and power through Groovy scripting. They are ideal for complex, customized automation tasks.

Real-Time Use Case for Jenkins Pipelines 🏗

Use Case: Consider a software development team that uses Jenkins for CI/CD. They have a declarative pipeline that builds, tests, and deploys their application to multiple environments automatically. Jenkins pipelines help the team ensure consistent, automated deployments, reducing manual errors and speeding up release cycles.

By incorporating Jenkins pipelines, the team streamlines their development process and ensures reliable, repeatable deployments.

Jenkins Plugin Integration:

Jenkins supports a vast ecosystem of plugins that extend its functionality. You can integrate Jenkins with various tools and services using plugins, making it highly adaptable to your specific requirements.

Setting Up Jenkins Agents 💻

Jenkins allows you to set up agents for executing build and deployment jobs. You can choose between Jenkins-managed agents and agents on your own infrastructure.

  • Jenkins-managed agents are hosted by Jenkins and are suitable for most scenarios. They provide a wide range of pre-installed tools and environments.

  • Self-hosted agents are agents that you set up and maintain in your own infrastructure. This option offers more control over the agent environment.

Tool Comparisons:

Jenkins is a highly customizable and extensible automation server, making it a popular choice for organizations with diverse CI/CD needs. It offers a wide range of plugins and integrations, but it may require more initial setup and configuration compared to Azure DevOps.