Jenkins is an open-source automation server that is widely used for continuous integration and continuous delivery (CI/CD) pipelines. It allows developers to automate the building, testing, and deployment of their software applications, making the development process faster and more efficient. For todays post this will show how to run this on Azure Virtual Machines and bootstrap the installation process.
For you to run this following command you can set up your Azure VM with the following parameters I’ve used this documentation but ran into a few hurdles so feel free to test this out.
Create a file in the cloud shell named jenkins.sh – can use nano/vim
#!/bin/bash
sudo apt update
sudo apt install openjdk-11-jre
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins
Then you can run a chmod +x jenkins.sh to make it executable and have that passed in the following command on the vm-create.
Ensure your spacing looks like this image below
az group create --name jenkins-on-azure --location eastus
az vm create \
--resource-group jenkins-on-azure \
--name jenkins-on-azure-demo \
--image Ubuntu2204 \
--admin-username "azureuser" \
--generate-ssh-keys \
--public-ip-sku Standard \
--custom-data jenkins.sh
Your output will show the machine in a running state with your public ip address that was generated from the previous CLI now we have to create a inbound rule to access Jenkins.
az vm open-port \
--resource-group jenkins-on-azure \
--name jenkins-on-azure-demo \
--port 8080 --priority 1010 \
Now after you run this command you should see the output like this
Let’s now login into the server via ssh as ssh azureuser@<public-ip>
Then you want to run the following command if you get the input shown below no worries we can install sometimes this could be the initialization not loaded yet or perhaps our script didn’t work.
service jenkins status
In the event you run into this let’s open up nano jenkins.sh to create a new file and we will copy our earlier command and run through installation again.
If you get an error I had to do some troubleshooting but realized that one prompt needed a input for a “y” I reran the commands listed here for Ubuntu
https://www.jenkins.io/doc/book/installing/linux/
You can run this command and if you get output we can verify that jenkins is up and running also we can run systemctl status jenkins.
We should be ready to run the following command to access the UI
http://<ip-address>:8080
The prompt will show in the browser like this – we can now go back to our terminal to grab our initial password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
This will have two options to install community plugins/custom plugins you can choose them as your need of the CI server plugins you’ll need.
Once you set up your admin user and launch again this should be the finished Jenkins UI.
Conclusion
While you can run a CI tool of your choice and have this set up more simple such as a Marketplace container this was to show you how you can bootstrap this on a linux machine for the configuration. Some key factors to consider with running a CI server – authentication has to be limited and credentials can be highly privileged in nature for authorizing to run on behalf of the pipeline. Additionally you’d want to deny traffic to port 22 and put the service behind a load balancer, rather leaving this as open to direct to the machine. Consider using Just-In-Time native to Microsoft Azure for the duration based on management operations and scope this to /32 addresses as needed.