Continuous Integration and Continuous Delivery (CI/CD) with Jenkins on macOS. A Step-by-Step Guide


Continuous Integration (CI) and Continuous Delivery (CD) are software development practices that aim to improve the development and delivery process. CI focuses on automating the integration of code changes from multiple contributors into a shared repository. On the other hand, CD extends this concept by automating the process of delivering the integrated code to production.

The main goals of CI/CD are to increase efficiency, reduce manual errors, and deliver high-quality software at a faster pace. Jenkins, an open-source automation server, is a popular tool for implementing CI/CD pipelines.

1. Simple Use Case

Let’s consider a simple use case to understand the need for CI/CD. Imagine you are working on a web application, and your team is continuously making code changes. Without CI/CD, integrating these changes manually can be time-consuming and error-prone. CI/CD helps automate this process, ensuring that the application is built, tested, and deployed consistently.

2. Using Jenkins for CI/CD on macOS

Step 1: Install Jenkins

  1. Open a terminal on your macOS.

  2. Install Homebrew (if not already installed) by running the following command:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  3. Install Jenkins using Homebrew:

    brew install jenkins

  4. Start the Jenkins service

    brew services start jenkins

  5. Access Jenkins in your browser at http://localhost:8080. Retrieve the initial admin password by running:

    cat $HOME/.jenkins/secrets/initialAdminPassword

  6. Follow the Jenkins setup wizard to complete the installation. When asked, chose “Install Suggested Plugins”

Step 2: Create Your First Jenkins Pipeline

  1. Create a new pipeline:

    Click on “New Item” on the Jenkins dashboard. Enter a name for your pipeline (e.g., “MyFirstPipeline”) and select “Pipeline” as the project type. Click “OK” to create the pipeline.

  2. Configure your pipeline:

    In the pipeline configuration, scroll down to the “Pipeline” section. In the “Definition” dropdown, select “Pipeline Script” to write the pipeline script directly.

  3. Write a simple pipeline script:

     pipeline {
     agent any
    
     stages {
         stage('Build') {
             steps {
                 echo 'Building the application...'
                 // Add your build commands here. For example cd $PROJECT_FOLDER && mvn build
             }
         }
         stage('Test') {
             steps {
                 echo 'Running tests...'
                 // Add your test commands here. For example, mvn test
             }
         }
         stage('Deploy') {
             steps {
                 echo 'Deploying the application...'
                 // Add your deployment commands here. For example, mvn install
             }
         }
     }
    }
    

    Customize the script based on your project’s build, test, and deployment requirements.

  4. Save the pipeline configuration.

  5. Run the pipeline:

    • Click on “Build Now” to trigger the pipeline manually.
    • Monitor the progress in the Jenkins interface and view the console output for each stage.

    Congratulations! You’ve successfully created and executed your first Jenkins pipeline on macOS. This is just a basic example, and you can extend and customize your pipeline to fit your specific project needs. CI/CD with Jenkins simplifies and automates the software development lifecycle, allowing you to deliver high-quality software efficiently.

About the Author

Hello! I’m Basil Varghese, a seasoned DevOps professional with 16+ years in the industry. As a speaker at conferences like Hashitalks: India, I share insights into cutting-edge DevOps practices. With over 8 years of training experience, I am passionate about empowering the next generation of IT professionals.

In my previous role at Akamai, I served as an ex-liaison, fostering collaboration. I founded Doorward Technologies, which became a winner in the Hitachi Appathon, showcasing our commitment to innovation.

Let’s navigate the dynamic world of DevOps together! Connect with me on LinkedIn for the latest trends and insights.


DevOps Door is here to support your DevOps learning journey. Join our DevOps training programs to gain hands-on experience and expert guidance. Let’s unlock the potential of seamless software development together!