Build with Jenkins in Azure

Set Up Jenkins Master

Create the Jenkins VM from the solution template

Open the marketplace image for Jenkins in your web browser and select GET IT NOW from the left-hand side of the page. Review the pricing details and select Continue, then select Create to configure the Jenkins server in the Azure portal.

Azure portal dialog

In the Configure basic settings tab, fill in the following fields:

Configure basic settings

  • Use Jenkins for Name.
  • Enter a User name. The user name must meet specific requirements.
  • Select Password as the Authentication type and enter a password. The password must have an upper case character, a number, and one special character.
  • Use myJenkinsResourceGroup for the Resource Group.
  • Choose the East US Azure region from the Location drop-down.

Select OK to proceed to the Configure additional options tab. Enter a unique domain name to identify the Jenkins server and select OK.

Set up additional options

Once validation passes, select OK again from the Summary tab. Finally, select Purchase to create the Jenkins VM. When your server is ready, you get a notification in the Azure portal:

Jenkins is ready notification

Connect to Jenkins

Navigate to your virtual machine (for example, in your web browser. The Jenkins console is inaccessible through unsecured HTTP so instructions are provided on the page to access the Jenkins console securely from your computer using an SSH tunnel.

Unlock jenkins

Set up the tunnel using the ssh command on the page from the command line, replacing username with the name of the virtual machine admin user chosen earlier when setting up the virtual machine from the solution template.

ssh -L <username>@<public DNS name of instance you just created>

After you have started the tunnel, navigate to http://localhost:8080/ on your local machine.

Get the initial password by running the following command in the command line while connected through SSH to the Jenkins VM.

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

Unlock the Jenkins dashboard for the first time using this initial password.

Unlock jenkins

Select Install suggested plugins on the next page and then create a Jenkins admin user used to access the Jenkins dashboard.

Jenkins is ready!

The Jenkins server is now ready to build code.

Create your first job

Select Create new jobs from the Jenkins console, then name it mySampleApp and select Freestyle project, then select OK.

Create a new job

Select the Source Code Management tab, enable Git, and enter the following URL in Repository URL field:

Define the Git repo

Select the Build tab, then select Add build step, Invoke Gradle script. Select Use Gradle Wrapper, then enter complete in Wrapper location and build for Tasks.

Use the Gradle wrapper to build

Select Advanced.. and then enter complete in the Root Build script field. Select Save.

Set advanced settings in the Gradle wrapper build step

Build the code

Select Build Now to compile the code and package the sample app. When your build completes, select the Workspace link for the project.

Browse to the workspace to get the JAR file from the build

Navigate to complete/build/libs and ensure the gs-spring-boot-0.1.0.jar is there to verify that your build was successful. Your Jenkins server is now ready to build your own projects in Azure.

Update Jenkins DNS

Make sure you update the Jenkins DNS name in Managed Jenkins -> Configure System -> Administrative monitors configuration -> Jenkins URL. Otherwise, the agent won’t be able to connect with the master.

Allow JNLP

Since the slave/agent connects with master via JNLP, make sure JNLP is allowed. In Jenkins, under Configure Global Security -> TCP port for JNLP agents, select Fixed and specify a port, for example, 12345.
Jenkins JNLP

Make sure you add a corresponding inbound security rule for the Jenkins master. In Azure, you add the rule in the Network Security Group for the Jenkins master:
JNLP port

Install the Azure plugins

Since you deployed Jenkins on Azure using the solution template, the Azure Credential Plugin and Azure Container Agents are already installed.

I ran into an issue I have a Jenkins Master in Azure