Setting Up a CI/CD Pipeline with Jenkins, GitHub Actions, or CircleCI
Tags: cicd, github, jenkins, circleci
Published: 2024-06-03 07:49:51

Continuous Integration and Continuous Deployment (CI/CD) pipelines have become essential for modern software development, allowing teams to automate the testing, integration, and deployment of code. In this blog post, we'll explore how to set up a [CI/CD pipeline](https://www.redhat.com/en/topics/devops/what-cicd-pipeline) using three popular tools: [Jenkins](https://www.janbasktraining.com/blog/jenkins-tutorial/), GitHub Actions, and CircleCI. Each tool has its unique features and strengths, so let's dive in to see how they can be leveraged for efficient and effective CI/CD processes.

## 1. Setting Up a CI/CD Pipeline with Jenkins

Jenkins is one of the most popular open-source automation servers. It offers a robust and flexible way to set up CI/CD pipelines.

**Step-by-Step Guide:**

**1. Install Jenkins:**

- Download and install Jenkins from the official site.
- Follow the setup wizard to complete the installation.

**2. Configure Jenkins:**

- Install necessary plugins, such as Git, GitHub, and Pipeline plugins.
- Go to "Manage Jenkins" > "Manage Plugins" and search for these plugins to install them.

**3. Create a New Pipeline Job:**

- Navigate to "New Item" and select "Pipeline" to create a new job.
- Name your job and click "OK".

**4. Set Up Pipeline Script:**

- In the pipeline configuration, choose "Pipeline script" and enter your Jenkinsfile script. A basic example:

```
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
                sh 'make build'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing...'
                sh 'make test'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying...'
                sh 'make deploy'
            }
        }
    }
}
```

- Save the configuration.

**5. Run the Pipeline:**

- Click "Build Now" to trigger the pipeline. Jenkins will execute the defined stages.

## 2. Setting Up a CI/CD Pipeline with GitHub Actions

GitHub Actions is a powerful CI/CD tool integrated directly into GitHub, making it easy to automate workflows from within your repositories.

**Step-by-Step Guide:**

**1. Create a GitHub Repository:**

- If you don't have a repository, create one on GitHub.

**2. Create a Workflow File:**

- In your repository, create a .github/workflows directory.
- Add a new file named ci-cd.yml in this directory.

**3. Define the Workflow:**

- Add the following YAML configuration to ci-cd.yml:

```
name: CI/CD Pipeline

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'

    - name: Install dependencies
      run: npm install

    - name: Run tests
      run: npm test

    - name: Deploy
      run: npm run deploy
```

- This configuration triggers the pipeline on every push to the main branch, checks out the code, sets up Node.js, installs dependencies, runs tests, and deploys the application.

**4. Commit and Push:**

- Commit and push the .github/workflows/ci-cd.yml file to your repository.

**5. View Workflow Runs:**

Go to the "Actions" tab in your GitHub repository to see the workflow runs and their statuses.

## 3. Setting Up a CI/CD Pipeline with CircleCI

CircleCI is another popular CI/CD tool that provides powerful automation capabilities.

**Step-by-Step Guide:**

**1. Sign Up and Link Your Repository:**

- Sign up for CircleCI and link your GitHub repository.

**2. Add Configuration File:**

- In your repository, create a .circleci/config.yml file.

**3. Define the Pipeline:**

- Add the following YAML configuration to config.yml:

```
version: 2.1

jobs:
  build:
    docker:
      - image: circleci/node:14
    steps:
      - checkout
      - run: npm install
      - run: npm test
      - run: npm run deploy

workflows:
  version: 2
  build_and_deploy:
    jobs:
      - build
```

- This configuration defines a job that uses a Node.js Docker image, checks out the code, installs dependencies, runs tests, and deploys the application.

**4. Commit and Push:**

- Commit and push the.circleci/config.yml file to your repository.

**5. Monitor the Pipeline:**

- Go to the CircleCI dashboard to monitor the pipeline execution and view detailed logs.

## Conclusion

Setting up a CI/CD pipeline is crucial for automating your software development process, ensuring high-quality code, and accelerating deployment cycles. Jenkins, GitHub Actions, and CircleCI are all powerful tools that can help you achieve these goals. Each has its unique strengths: Jenkins offers extensive customization and plugin support, GitHub Actions provides seamless integration with GitHub repositories, and CircleCI excels in ease of setup and use with Docker.

By following the steps outlined above, you can set up a robust CI/CD pipeline with any of these tools, tailored to your specific needs and workflows. Happy coding and automating!