Test Automation: Jenkins Controller Agent setup in GCP: Ubuntu VM (Part 1)

Girish Nair
8 min readAug 8, 2022

--

Hello everyone, in this series of articles we will explore how can we install and configure Jenkins, different components: Java, Maven, Git, Docker, and accordingly set up Jenkins Controller Agent in Ubuntu VM instances hosted in Google Cloud Platform (GCP).

We will leverage free tier account benefits available for GCP to set up the Jenkins pipeline and run our test automation scripts via these pipelines in docker containers. Also, we will configure our pipelines to build a Docker image of our test automation framework and push the same to our Docker hub account. Hope you guys are excited about this series, there are a lot of topics to cover so this series might extend to quite a few more parts, so will request you to please be a little patient. Let’s get started.

In this Part 1 of the series, we will first register for a new GCP account and create a new Ubuntu VM instance in Google Cloud Platform (GCP).

Step 1: Creating an account in GCP and accessing the dashboard

To create a new account in GCP, head on over to the Signup page and click on the button “Get started for free”

GCP Signup

One of the benefits of signing up for a GCP account is that new customers get 300 USD in free credits which can be used for hands-on, learning and exploring a wide range of services offered by GCP including Compute Engine service which we will be using in our upcoming articles. Earlier we had the option to utilize these $300 credits for a period of 1 year, but recently they have now reduced it to 90 days. Anyways, it’s still a sufficient duration to try out and use it for our learning purposes.

It would be beneficial if you have a google account for the registration. Also, setup steps are relatively easy and you will mainly require a credit or debit card for creating an account, do note that you will be initially charged a nominal amount of INR 1 or 2 for just verifying your card details, post which your account will be created. You can select Account Type as Individual.

You can refer video which is really helpful. Here is another video that can also be referred to.

GCP Account Created

Congratulations!! you have successfully created an account with GCP, now let’s move forward.

Step 2: Exploring different dashboard components seen in GCP

Post successful registration, you will be navigated to GCP Dashboard. Let’s explore the different components and options available under it.

Projects section: In GCP, primarily you will be working under some specific project, you can view the selected project to view details or create a new Project. In my case, I have created a new Project called “DemoProject”.

When you click on the available Project Name in your dashboard, you will be presented with a window that shows the available Projects and provides you with an option to create a “New Project”.

You can click on the button “NEW PROJECT” to create one, you just need to specify any applicable name and hit on Create button. You will see a tick icon next to the project that you are currently using.

Additionally in the top menu bar, there is a bell icon which can be used to view all recent notifications, also you will see a gift box icon on the menu bar if you click on the same, it will display the details of your Free trial status: no of days remaining and the amount that is pending for use. (Note: Do not click on Activate button, just Dismiss the message if you have clicked on the gift box icon)

Step 3: Create a VM instance using GCP: Compute Engine Service.

To create a new VM instance, we will have to navigate to the VM Instances page, click on the hamburger menu available in the top left corner, and select the highlighted options. (under Compute Engine and then VM instances)

Compute Engine -> VM Instances

When you navigate to the VM instances page for the first time, you will get an option to enable the Compute Engine API, do so by clicking on the “Enable” button, this might take a few minutes. In GCP, generally for every service that you use you need to enable API for the same. Post this step, you will be navigated to your VM instance dashboard.

VM Instances dashboard

Now, we will proceed with instance creation, click on the button “CREATE INSTANCE” available in the dashboard, and you will be navigated to the “Create an instance” page. In GCP, we can create instances via multiple options which are available in the left pane, in our case we use the option “New VM Instance from scratch”

As you can see above, the Monthly estimate will be displayed in the right pane section, this will vary based on a number of parameters for example vCPU, RAM, storage, OS license, etc. Do not worry as these are monthly running charges incurred, in our case, we will probably be using our instances for a couple of hours, so it shouldn’t matter. Since we are using Free tier benefits, usage costs will be accordingly adjusted from the free credits limit.

Let's proceed, so first, we need to provide a name for our instance, you can hover over the question mark icon to view the naming guidelines that need to be followed. Post entering an instance name you can select the Region and Zone options. Similar to AWS, GCP also provides services in many regions and zones. For more details, you can visit Regions & Zones. Select any available region which is close to your geographical location. Do note that Region and Zone details cannot be changed post instance creation so choose accordingly.

Next up, we need to select the Machine configuration similar to AWS, GCP also offers a wide array of machine configurations and family types based on various criteria such as memory-optimized, compute-optimized, GPU, general purpose, etc.

In GCP we have an additional feature that is not available in AWS or Azure is that you can create a custom instance size based on your requirements which is really cool. You can use the slider to adjust cores and memory as per your needs.

In our case, we will just use the default option: General-Purpose machine family and e2-medium series.

Next up is the Boot disk which is the OS image that can be selected, click on the “CHANGE” button to update.

Change Boot disk

We will use Ubuntu public image, v18.04 LTS, and keep disk size: 10GB.

Under Firewall, allow HTTP & HTTPS traffic. Additionally, we can allow specific ports: 8080 post instance creation from Firewall rules.

Expand the Advanced options section, and navigate to Network Interfaces, here we will assign a static public IP address to our instance. By default, this option will be set to Automatic which indicates that every time you start and stop your instances, the public IP address for your instance will change. To avoid this, we will assign a static IP address that will not change, this is similar to Elastic IP in AWS. In GCP, external IP refers to public IP and internal IP refers to private IP.

Under External IPv4 address select the Ephemeral option and click on the button “Create IP Address” to create a static IP.

You can give any name for the static IP and click on the Reserve button.

Post this, the IP will be displayed in the External IPv4 address dropdown, finally, we are almost done just review all the selected details and click on the button “Create” to complete the process. Do note that you will see the message “Your free trial credit will be used for this VM instance”. It might take a couple of minutes to fully set up and start your VM instance.

You can view the current instance status in your dashboard. (Note: I have removed my Internal & External IP address details from the below image)

A green tick indicates that the instance is up & running. you can stop the instance by clicking on the checkbox next to the Status column and the Stop button available in the top menu bar.

Step 4: Connecting to your VM instance

GCP offers many options to connect to your instance using gcloud or private SSH, also you can use Putty to connect to your instance. For now, we will just verify using the “Open in Browser window” option. This will open a new browser window and you will be connected to your VM instance.

Post connect, you can just run an update in your VM instance using the below command. This might take a few seconds post which all the available libraries in your VM instance will be updated.

sudo apt-get update -y

And that’s it, we have created an Ubuntu VM instance in GCP. That’s all for this Part 1 article, in the next article we will move forward and install/set up additional components: Java, Maven, Git, and Docker in this instance, and finally set up Jenkins which will act as the Controller node.

Thanks for reading and stay tuned for Part 2!!

--

--