Skip to content

This repository provides a complete walkthrough for setting up Jenkins on GCP, covering everything from initial VM creation to accessing Jenkins through secure methods. Whether you're new to Jenkins or GCP, this guide will get you up and running quickly and repo with jenkinsfile for CI

Notifications You must be signed in to change notification settings

Mahadhav1999/sample-jenkinsci-with-jenkinsfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Sample Jenkins CI with Jenkinsfile

This repository provides a comprehensive walkthrough for setting up Jenkins on Google Cloud Platform (GCP) and integrating it with a GitHub repository containing a Jenkinsfile.

Whether you’re new to Jenkins or GCP, this guide will help you set up a working Continuous Integration (CI) pipeline quickly.


βœ… Prerequisites

Before starting, ensure you have:

  • A Google Cloud account with Compute Engine enabled.
  • A GitHub account.
  • Basic knowledge of Linux commands.
  • A sample GitHub repository with some Java code (or any language) and a Jenkinsfile.

πŸ“ Step-by-Step Setup

Step 1: Create a Sample GitHub Repository

  1. Go to GitHub β†’ create a new repository. Example: sample-jenkinsci-with-jenkinsfile.
  2. Add some sample Java (or Python/Node) code. Example: HelloWorld.java.
  3. Create a file named Jenkinsfile at the root of the repo with a minimal pipeline:
pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building the project...'
            }
        }
        stage('Test') {
            steps {
                echo 'Running tests...'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying application...'
            }
        }
    }
}

βœ… Ensure the filename is exactly Jenkinsfile (case-sensitive).


Step 2: Create a VM on GCP & Install Jenkins

  1. Go to GCP Console β†’ Compute Engine β†’ VM Instances β†’ Create Instance.

    • Name: jenkins-ci
    • Machine type: e2-medium (2 vCPUs, 4GB RAM)
    • Boot disk: Ubuntu 22.04 LTS
    • Allow HTTP & HTTPS traffic
  2. SSH into VM and install Jenkins. You can follow this guide πŸ‘‰ Jenkins Setup and Installation.


Step 3: Access Jenkins UI

  1. Get VM External IP from GCP.

  2. Open in browser:

    http://<external-ip>:8080
    
  3. Unlock Jenkins:

    sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  4. Install suggested plugins and create an Admin user.


Step 4: Create a New Pipeline Job in Jenkins

  1. Go to Jenkins Dashboard β†’ Click New Item.
  2. Enter job name: first-pipeline-job-with-jenkinsfile.
  3. Select Pipeline β†’ Click OK.

Step 5: Configure GitHub Repository in Jenkins

  1. In job configuration β†’ Scroll to Pipeline section.

  2. Set Definition β†’ Pipeline script from SCM.

  3. SCM β†’ Select Git.

  4. Enter your GitHub Repository URL. Example:

    https://github.com/<your-username>/sample-jenkinsci-with-jenkinsfile.git
    
  5. If repo is private β†’ click Add Credentials β†’ provide GitHub username & token.


Step 6: Configure Branch & Script Path

  1. Scroll to Branches to build section.

    • Branch Specifier: main (or master, depending on your repo).
  2. Scroll to Script Path β†’ set as Jenkinsfile.

⚠️ Important: The filename in GitHub and Script Path must match exactly (case-sensitive).


Step 7: Save & Build

  1. Click Save.
  2. Go to job dashboard β†’ Click Build Now.
  3. Open Console Output β†’ Jenkins will show logs of each stage (Build, Test, Deploy).

Step 8: Verify Build Status

  • βœ… SUCCESS β†’ All stages executed properly.
  • ❌ FAILURE β†’ Build or Test step failed.
  • ⚠️ UNSTABLE β†’ Build successful but some tests failed.

🎯 Final Result

You now have a Jenkins CI Pipeline on GCP VM that:

  • Pulls code from GitHub.
  • Runs Build, Test, Deploy stages via Jenkinsfile.
  • Can auto-trigger builds using webhooks or pollSCM configuration.

About

This repository provides a complete walkthrough for setting up Jenkins on GCP, covering everything from initial VM creation to accessing Jenkins through secure methods. Whether you're new to Jenkins or GCP, this guide will get you up and running quickly and repo with jenkinsfile for CI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published