Provisioning a Linux Virtual Machine with Jenkins installed & configured using Azure ARM Templates & cloud-init

This blog illustrates how to automate a Linux Virtual Machine with the required infrastructure setup with Jenkins installation, configuration & validation using Azure ARM Template & cloud-init

In the early years of internet application development, hardware resources and systems administration were primarily performed manually.  System administrators manually provisioned and managed hardware resources based on configuration data while still juggling configuration data. In today’s world, where everything is achieved at the touch of a button, more and more companies are moving towards automation to remove any bottlenecks caused by the manual way of doing things.

Need for Automation

Based on our requirement, we are going to create an Ubuntu VM and the required infrastructure setup in Azure Cloud with Jenkins installed and configured for creating and building a Pipeline Job.

It would take a long time to complete this with a manual process in case of provisioning ‘n’ number of VM’s according to our requirements. This may cause a risk factor while provisioning the VM with the required infrastructure and Jenkins Configurations. For this, automation with Azure ARM Templates is the perfect strategy for fulfilling the requirements.

Azure supports two provisioning agents:

 Linux Agent: It is an Azure platform-specific agent also known as WALA used to provision and configure VMs and handle Azure Extensions.

 Cloud-init: Cloud-init is a service that sets up your VM instance with the required software installed, configured, and ready to use. The service starts at boot and uses the metadata provided by the cloud provider.

 Why Cloud-init

We opt for cloud-init instead of a Linux agent to support the existing cloud-init customers by using their existing cloud-init scripts and the new customers can also take advantage of the rich cloud-init configuration functionalities.

Cloud-init does not require any additional settings for configuring Linux systems.

Unlike Linux agents, cloud-init configurations do not have time constraints and deployment fails by timing out.

Cloud-init Capabilities

  • Adding users and groups
  • Writing out arbitrary files
  • Adding YUM repositories
  • Running commands on first boot

Azure ARM template creates the following resources in the Azure account

  • Public IP to associate with Network Interface
  • Network Interface to attach with VM
  • Virtual Machine with required configurations
  • OS Disk to attach with VM as an additional storage device

The ARM template & Script for Jenkins installation and configuration is available in the GitHub repository link given below.

https://github.com/poovaragavan-a/Azure-ARM-.git

Networking components diagram with respective Azure ARM snippets

Picture1

Process Summary

Using the ARM Template we create a Virtual Machine with Ubuntu OS with the existing Resource Group and the respective Networking Components.

Using cloud-init in custom data we install the prerequisites – jdk & git, then install Jenkins Tool.

Jenkins installation & configuration

We achieve configuring of Jenkins through automation in two steps:

  • Disable the Initial Setup Wizard by creating a jenkins.install.UpgradeWizard.state with “2.0” content.
  • Provide a secure login id and password for default admin account using the basic-security.groovy file with respective content as given in the git repository within the init.groovy.d folder.

Groovy file to provide a secure Jenkins login credentials

Picture2

Please check the reference link for further clarification regarding the configuration of Jenkins.

Next, we get the Jenkins-cli.jar to the instance and install the required plugins with Jenkins CLI commands.

Code commit repo to store the Jenkins file

Picture2

Validating the Jenkins installation & configuration

Finally, we validate Jenkins by creating and building the Job with Jenkins CLI commands by retrieving the Jenkins File from the CodeCommit Repository to configure the Job.

Output

Sample Job Console Output

Picture4

Note:

Kindly check with the reference links for the jenkins configuration groovy files.

We hope this blog gets you through the automating process for provisioning a VM with Jenkins installation and configuration.

Get in touch with us if you need further assistance on the above configuration.

Published On: July 1, 2022

Updated on July 28, 2022

Sharing is caring!

In Blog
Subscribe to our Newsletter1CloudHub