Mastering GCP Setting Up CICD with Jenkins, Git, Docker, & Maven

Learn how to create a GCP account, create a project, enable essential GCP APIs, and set up a virtual machine instance with Ubuntu. We'll install Git, Docker, Maven, and Jenkins, and open port 8080 for Jenkins to complete your CI/CD environment.


Follow along step-by-step to supercharge your development workflow with the Google Cloud Platform. Whether you're a beginner or an experienced developer, this guide will help you streamline your CI/CD process. 

Setting up a CI/CD pipeline on the Google Cloud Platform (GCP) with Jenkins, Git, Docker, and Maven involves several steps. This guide will walk you through the process:


Prerequisites:

1. A Google Cloud Platform account with billing enabled.

2. A Google Cloud Compute Engine VM instance for hosting Jenkins.

3. A Git repository, e.g., hosted on GitHub, GitLab, or Bitbucket.

4. A Docker Hub account for Docker image hosting.

5. A basic understanding of Jenkins, Git, Docker, and Maven.


Step 1: Launch a Compute Engine VM for Jenkins:

1. Log in to your GCP Console.

2. Create a Compute Engine VM instance. Make sure it has enough resources to run Jenkins smoothly.

3. Allow HTTP and HTTPS traffic in the VM's firewall rules.

4. Connect to the VM via SSH.


Step 2: Install Jenkins on GCP VM:

1. Update the VM packages: `sudo apt-get update`.

2. Install Java, as Jenkins requires it: `sudo apt-get install openjdk-8-jdk`.

3. Install Jenkins by adding the official repository and installing the package. Follow the instructions for your Linux distribution. For example:

Copy this below commands:

   wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -

   sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

   sudo apt-get update

   sudo apt-get install jenkins


4. Start Jenkins: `sudo systemctl start jenkins`.

5. Enable Jenkins to start at boot: `sudo systemctl enable jenkins`.


Step 3: Access Jenkins Web UI:

1. Get the initial admin password from the server: `sudo cat /var/lib/jenkins/secrets/initialAdminPassword`.

2. Go to your VM's external IP address, port 8080 (e.g., http://YOUR_VM_IP:8080).

3. Enter the initial admin password and follow the setup wizard.


Step 4: Install Jenkins Plugins:

1. Install necessary Jenkins plugins, such as Git, Docker, and Pipeline.

2. Configure Git and Docker integrations in Jenkins.


Step 5: Set Up Your CI/CD Pipeline:

1. Create a new Jenkins pipeline or freestyle project.

2. Configure your project to pull code from your Git repository.

3. Define build and test steps, and add the necessary Maven goals to build your project.

4. Add a post-build step to build and publish Docker images.


Step 6: Secure Your Secrets:

1. Use Jenkins credentials to securely store secrets like API keys and Docker credentials.

2. Integrate with Google Secret Manager for added security.


Step 7: Configure Webhooks:

1. In your Git repository (e.g., GitHub), configure a webhook to notify Jenkins of changes.

2. Use the payload URL of your Jenkins instance, e.g., http://YOUR_VM_IP:8080/github-webhook/.


Step 8: Test the CI/CD Pipeline:

1. Push changes to your Git repository.

2. Monitor Jenkins for automated builds and deployments.

3. Verify that Docker images are built and pushed to Docker Hub.


Step 9: Continuous Deployment:

1. Set up a deployment environment in GCP, such as Google Kubernetes Engine (GKE) or Compute Engine.

2. Configure your Jenkins pipeline to deploy your Docker images to the production environment.


This guide provides a high-level overview of setting up a CI/CD pipeline on GCP using Jenkins, Git, Docker, and Maven. The specific configurations and steps can vary depending on your project's requirements, so be sure to adapt these steps to your specific use case and follow best practices for CI/CD pipelines and security.

Comments