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.
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.
- Go to GitHub β create a new repository.
Example:
sample-jenkinsci-with-jenkinsfile
. - Add some sample Java (or Python/Node) code.
Example:
HelloWorld.java
. - 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).
-
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
- Name:
-
SSH into VM and install Jenkins. You can follow this guide π Jenkins Setup and Installation.
-
Get VM External IP from GCP.
-
Open in browser:
http://<external-ip>:8080
-
Unlock Jenkins:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
-
Install suggested plugins and create an Admin user.
- Go to Jenkins Dashboard β Click New Item.
- Enter job name:
first-pipeline-job-with-jenkinsfile
. - Select Pipeline β Click OK.
-
In job configuration β Scroll to Pipeline section.
-
Set Definition β Pipeline script from SCM.
-
SCM β Select Git.
-
Enter your GitHub Repository URL. Example:
https://github.com/<your-username>/sample-jenkinsci-with-jenkinsfile.git
-
If repo is private β click Add Credentials β provide GitHub username & token.
-
Scroll to Branches to build section.
- Branch Specifier:
main
(ormaster
, depending on your repo).
- Branch Specifier:
-
Scroll to Script Path β set as
Jenkinsfile
.
- Click Save.
- Go to job dashboard β Click Build Now.
- Open Console Output β Jenkins will show logs of each stage (Build, Test, Deploy).
- β SUCCESS β All stages executed properly.
- β FAILURE β Build or Test step failed.
β οΈ UNSTABLE β Build successful but some tests failed.
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.