1. Create a GCP Compute Engine


Remember to Allow Http and Https traffic and enter the following script to install Jenkins:

sudo apt update
sudo apt install openjdk-8-jdk -y
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 update
sudo apt install jenkins -y

sudo /etc/init.d/jenkins start
2. Set up VPC firewall rule to access VM from browser

The VM is now isolated from the Internet, we need to open port 8080 (default Jenkins port):

  • Go to VPC networks > Firewall rules menu
  • Choose Create firewall rule

Specify the as above, this config will allow port 8080 of Jenkins server to be accessed from any IP address.

  • Go to VM and add tag jenkins to the Jenkins VM:
Setup Jenkins
  • Now open <VM-ip>:8080 to setup Jenkins. You should see:
  • SSH to the VM and run
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

to get the initial password of Jenkins. Paste it to the page.

  • Install plugins and create admin user

Now Jenkins is ready: