How to Host Jenkins on Azure

Here’s how to get Jenkins on Azure. The following is based on: Azure Friday: Host Jenkins on Azure - with some added modifications to make sure you are SSH tunneling into the Jenkins app instead of accessing over an insecure channel.

Here are the steps we’ll follow:

1. Deploy Azure Jenkins Template, which will provision Jenkins on a VM for you.
2. Get Jenkins VM IP Address
3. Open Port 8080 on the Azure Network Security Group
4. SSH to VM (with either Putty or bash)
5. Get Temp Admin Password
6. Launch Jenkins Admin App
7. Setup Jenkins
8. Create Admin User
9. Restart Jenkins
10. Login
11. Happy Dance

Deploy Azure Jenkins Template

1. Go to http://aka.ms/azjenkins

2. Click ‘Deploy to Azure’

3. Complete the form, click ‘Purchase’ and wait for it to provision the Linux VM.

Get Jenkins VM IP Address

1. Get the Jenkins VM IP Address from the Overview blade, you will need this later.

Open Port 8080

The Jenkins Admin app is on port 8080, but, at the time of this writing, port 8080 is not open in the Network Security Group created by the Azure Deployment template.

1. In the Azure Portal, find the Network Security Group that was just created.
2. If you don’t see 8080 there, then click Inbound Security Rules, then click Add

3. Give it a name and set Port range to 8080

Connect to VM

We are going to connect to the VM via SSH to:
1. Get the temp Jenkins Admin password
2. Launch the Jenkins Admin app

You can use an SSH client such as Putty or bash.

Since the VM does not have an SSL cert, you should create a secure tunnel to port 8080 and access via 127.0.0.1 instead of going to the website over the unencrypted internet.

Connect via Putty

1. Download and Open Putty
2. Enter the Jenkins VM Public IP, enter a name ‘jenkinsvm’ and then click Save.

3. In the left nav, click Connection -> SSH -> Tunnels
4. Set the following values:

  • Source port: 8080
  • Destination: 127.0.0.1:8080

5. Click “Add” button and you will see L8080 127.0.0.1:8080 in the textarea.

6. Go back to the “Session” tab and click “Save” button to save the port forward that you just entered.

7. Click Open and click Yes if you see the following dialog:

8. Login using the username and password you used to create the Jenkins VM.

You will see an output like the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
login as: jongadmin
jongadmin@40.83.216.117's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-53-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Thu Apr 6 21:23:30 UTC 2017
System load: 0.0 Processes: 138
Usage of /: 7.6% of 28.80GB Users logged in: 0
Memory usage: 15% IP address for eth0: 10.0.0.4
Swap usage: 0%
Graph this data and manage this system at:
https://landscape.canonical.com/
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
93 packages can be updated.
61 updates are security updates.
Your Hardware Enablement Stack (HWE) is supported until April 2019.
Last login: Thu Apr 6 21:23:30 2017 from 167.220.1.142
jongadmin@jenkinsVM:~$

Connect via bash

1. Open a bash command prompt and run the following command:

Replace jongadmin with the username you created the Jenkins VM with. Replace 40.83.216.117 with your Jenkins VM IP Address

1
ssh -L 127.0.0.1:8080:40.83.216.117:8080 jongadmin@40.83.216.117

See my blog post here, for instructions on how to run bash on Windows.

This will create an ssh connection and create a secure tunnel to port 8080 (the Jenkins Admin app)

2. Enter yes and hit enter if you see the following:

1
2
3
4
jong@JONGHPDESKTOP:/mnt/c/Windows/System32$ ssh -L 8080:127.0.0.1:8080 jongadmin@40.83.216.117
The authenticity of host '40.83.216.117 (40.83.216.117)' can't be established.
ECDSA key fingerprint is 02:25:0e:74:b1:01:e6:f1:96:73:7b:b6:42:dd:c4:e0.
Are you sure you want to continue connecting (yes/no)?

You will see an output similar to the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
jong@JONGHPDESKTOP:~$ ssh -L 127.0.0.1:8080:40.83.216.117:8080 jongadmin@40.83.216.117
jongadmin@40.83.216.117's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-53-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Thu Apr 6 21:22:42 UTC 2017
System load: 0.0 Processes: 137
Usage of /: 7.6% of 28.80GB Users logged in: 0
Memory usage: 15% IP address for eth0: 10.0.0.4
Swap usage: 0%
Graph this data and manage this system at:
https://landscape.canonical.com/
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
93 packages can be updated.
61 updates are security updates.
Your Hardware Enablement Stack (HWE) is supported until April 2019.
Last login: Thu Apr 6 21:22:42 2017 from 167.220.1.142
jongadmin@jenkinsVM:~$

Get Temp Admin Password via SSH

The next step is to connect to the Jenkins Admin app, but we first need to get the temp password that is stored on the VM.

1. In SSH terminal, enter the following command to get the temp admin password

1
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

2. Copy that password to your clipboard.

Launch Jenkins Admin App

1. Open a browser and go to http://127.0.0.1:8080

You will see the following:

2. Enter the temp admin password that you retrieved in the previous step.

Setup Jenkins

1. Click Install Suggested Plugins

Create First Admin User

1. Complete the form to create an admin user and then click continue.

2. Click Restart

Login to Jenkins

1. Hit http://127.0.0.1:8080 again and enter the credentials you created in the previous step.

You now have Jenkins running on Azure!

Share