Tutorial: Use Azure Container Instances as a Jenkins build agent
Important
Many Azure services have Jenkins plug-ins. Some of these plug-ins will be out of support as of February 29, 2024. Azure CLI is the currently recommended way to integrate Jenkins with Azure services. For more information, refer to the article Jenkins plug-ins for Azure.
Azure Container Instances (ACI) provides an on-demand, burstable, and isolated environment for running containerized workloads. Because of these attributes, ACI makes a great platform for running Jenkins build jobs at a large scale. This article shows you how to deploy an ACI and add it as a permanent build agent for a Jenkins controller.
For more information on Azure Container Instances, see About Azure Container Instances.
Prerequisites
- Azure subscription: If you don't have an Azure subscription, create a free Azure account before you begin.
- Jenkins server: If you don't have a Jenkins server installed, create a Jenkins server on Azure.
Prepare the Jenkins controller
Browse to your Jenkins portal.
From the menu, select Manage Jenkins.
Under System Configuration, select Configure System.
Verify that the Jenkins URL is set to the HTTP address of your Jenkins installation -
http://<your_host>.<your_domain>:8080/
.From the menu, select Manage Jenkins.
Under Security, select Configure Global Security.
Under Agents, specify Fixed port and enter the appropriate port number for your environment.
Configuration example:
Select Save.
Create Jenkins work agent
Browse to your Jenkins portal.
From the menu, select Manage Jenkins.
Under System Configuration, select Manage Nodes and Clouds.
From the menu, select New Node.
Enter a value for Node Name.
Select Permanent Agent.
Select OK.
Enter a value for Remote root directory. For example,
/home/jenkins/work
Add a Label (Labels are used to group multiple agents into one logical group. An example of a label would be
linux
to group your Linux agents.) with the value oflinux
.Set Launch method to Launch agent by connecting to the master.
Verify that all required fields have been specified or entered:
Select Save.
On the agent status page, you should see the
JENKINS_SECRET
andAGENT_NAME
. The following screen shot shows how to identify the values. Both values are needed when you create the Azure Container Instance.
Create Azure Container Instance with CLI
Use az group create to create an Azure resource group.
az group create --name my-resourcegroup --location westus
Use az container create to create an Azure Container Instance. Replace the placeholders with the values obtained when you created the work agent.
az container create \ --name my-dock \ --resource-group my-resourcegroup \ --ip-address Public --image jenkins/inbound-agent:latest \ --os-type linux \ --ports 80 \ --command-line "jenkins-agent -url http://jenkinsserver:port <JENKINS_SECRET> <AGENT_NAME>"
Replace
http://jenkinsserver:port
,<JENKINS_SECRET>
, and<AGENT_NAME>
with your Jenkins controller and agent information. After the container starts, it will connect to the Jenkins controller server automatically.Return to the Jenkins dashboard and check the agent status.
Note
Jenkins agents connect to the controller via port
5000
, ensure that port is allowed inbound to the Jenkins Controller.
Create a build job
Now, a Jenkins build job is created to demonstrate Jenkins builds on an Azure container instance.
Select New Item, give the build project a name such as aci-demo, select Freestyle project, and select OK.
Under General, ensure that Restrict where this project can be run is selected. Enter linux for the label expression. This configuration ensures that this build job runs on the ACI cloud.
Under Build, select Add build step and select Execute Shell. Enter
echo "aci-demo"
as the command.Select Save.
Run the build job
To test the build job and observe Azure Container Instances manually start a build.
Select Build Now to start a build job. Once the job starts you'll see a status that's similar to the following image:
Click build #1 in the Build History.
Select Console Output to view the builds output.
Next steps
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for