Events
19 May, 18 - 23 May, 00
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article shows how to install Jenkins on an Ubuntu Linux VM with the tools and plug-ins configured to work with Azure.
In this article, you'll learn how to:
- Create a setup file that downloads and installs Jenkins
- Create a resource group
- Create a virtual machine with the setup file
- Open port 8080 in order to access Jenkins on the virtual machine
- Connect to the virtual machine via SSH
- Configure a sample Jenkins job based on a sample Java app in GitHub
- Build the sample Jenkins job
If you already have a Cloud Shell session open, you can skip to the next section.
Browse to the Azure portal
If necessary, log in to your Azure subscription and change the Azure directory.
Open Cloud Shell.
If you haven't previously used Cloud Shell, configure the environment and storage settings.
Select the command-line environment.
Create a test directory called jenkins-get-started
.
Switch to the test directory.
Create a file named cloud-init-jenkins.txt
.
Paste the following code into the new file:
#cloud-config
package_upgrade: true
runcmd:
- sudo apt install openjdk-17-jre -y
- curl -fsSL https://pkg.jenkins.io/debian-stable/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-stable binary/' | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
- sudo apt-get update && sudo apt-get install jenkins -y
- sudo service jenkins restart
Run az group create to create a resource group.
az group create --name jenkins-get-started-rg --location eastus
Run az vm create to create a virtual machine.
az vm create \
--resource-group jenkins-get-started-rg \
--name jenkins-get-started-vm \
--image UbuntuLTS \
--admin-username "azureuser" \
--generate-ssh-keys \
--public-ip-sku Standard \
--custom-data cloud-init-jenkins.txt
Run az vm list to verify the creation (and state) of the new virtual machine.
az vm list -d -o table --query "[?name=='jenkins-get-started-vm']"
As Jenkins runs on port 8080, run az vm open to open port 8080 on the new virtual machine.
az vm open-port \
--resource-group jenkins-get-started-rg \
--name jenkins-get-started-vm \
--port 8080 --priority 1010
Run az vm show to get the public IP address for the sample virtual machine.
az vm show \
--resource-group jenkins-get-started-rg \
--name jenkins-get-started-vm -d \
--query [publicIps] \
--output tsv
Key points:
--query
parameter limits the output to the public IP addresses for the virtual machine.Using the IP address retrieved in the previous step, SSH into the virtual machine. You'll need to confirm the connection request.
ssh azureuser@<ip_address>
Key points:
azureuser@jenkins-get-started-vm
.Verify that Jenkins is running by getting the status of the Jenkins service.
service jenkins status
Key points:
Get the autogenerated Jenkins password.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Using the IP address, open the following URL in a browser: http://<ip_address>:8080
Enter the password you retrieved earlier and select Continue.
Select Select plug-in to install.
In the filter box at the top of the page, enter github
. Select the GitHub plug-in and select Install.
Enter the information for the first admin user and select Save and Continue.
On the Instance Configuration page, select Save and Finish.
Select Start using Jenkins.
On the Jenkins home page, select Create a job.
Enter a job name of mySampleApp
, select Freestyle project, and select OK.
Select the Source Code Management tab. Enable Git and enter the following URL for the Repository URL value: https://github.com/spring-guides/gs-spring-boot.git
. Then change the Branch Specifier to */main
.
Select the Build tab, then select Add build step
From the drop-down menu, select Invoke Gradle script.
Select Use Gradle Wrapper, then enter complete
in Wrapper location and build
for Tasks.
Select Advanced and enter complete
in the Root Build script field.
Scroll to the bottom of the page, and select Save.
When the home page for your project displays, select Build Now to compile the code and package the sample app.
A graphic below the Build History heading indicates that the job is being built.
When the build completes, select the Workspace link.
Navigate to complete/build/libs
to see that the .jar
file was successfully built.
Your Jenkins server is now ready to build your own projects in Azure!
If you encounter any problems configuring Jenkins, refer to the Jenkins installation page for the latest instructions and known issues.
Events
19 May, 18 - 23 May, 00
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today