0
0
Jenkinsdevops~30 mins

Agent connection methods (SSH, JNLP) in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Jenkins Agent Connection Methods: SSH and JNLP Setup
📖 Scenario: You are setting up Jenkins agents to connect to the Jenkins master server. Agents can connect using different methods. Two common methods are SSH and JNLP (Java Network Launch Protocol). You will configure both connection methods step-by-step.
🎯 Goal: Build a simple Jenkins agent configuration using both SSH and JNLP connection methods. You will create the initial agent data, add connection details, apply the connection method logic, and finally display the configured agent connection info.
📋 What You'll Learn
Create a dictionary to hold agent names and their IP addresses
Add a configuration variable to specify the connection method (SSH or JNLP)
Use a loop to assign connection commands based on the connection method
Print the final agent connection commands
💡 Why This Matters
🌍 Real World
Jenkins agents need to connect to the master server to run jobs. SSH and JNLP are common ways to establish this connection securely.
💼 Career
Understanding how to configure Jenkins agents and their connection methods is essential for DevOps engineers managing CI/CD pipelines.
Progress0 / 4 steps
1
Create initial Jenkins agents data
Create a dictionary called agents with these exact entries: 'agent1': '192.168.1.10', 'agent2': '192.168.1.11', 'agent3': '192.168.1.12'
Jenkins
Need a hint?

Use curly braces to create a dictionary with the exact keys and values.

2
Add connection method configuration
Create a variable called connection_method and set it to the string 'SSH'
Jenkins
Need a hint?

Assign the string 'SSH' to the variable named connection_method.

3
Generate connection commands for agents
Create an empty dictionary called connection_commands. Then use a for loop with variables agent and ip to iterate over agents.items(). Inside the loop, if connection_method is 'SSH', set connection_commands[agent] to f"ssh user@{ip}". Otherwise, set it to f"java -jar agent.jar -jnlpUrl http://jenkins/computer/{agent}/slave-agent.jnlp".
Jenkins
Need a hint?

Use a for loop to go through agents and assign commands based on the connection method.

4
Display the agent connection commands
Use a for loop with variables agent and command to iterate over connection_commands.items(). Inside the loop, print the string f"{agent}: {command}".
Jenkins
Need a hint?

Print each agent name followed by a colon and its connection command.