CodeAlpha DevOps Internship — Task 2: Jenkins Remoting Project
Sets up a Jenkins controller and a separate remote agent node, connected via Jenkins Remoting over SSH, and runs a pipeline job that executes on the remote node — proving distributed builds, node isolation, and secure remote execution.
CodeAlpha_JenkinsRemotingProject/
├── docker-compose.yml # controller + agent containers
├── Jenkinsfile # pipeline that targets the remote node
├── Jenkinsfile.multi-node # bonus: 2 nodes, different labels
└── README.md
- Docker + Docker Compose installed
- An SSH keypair (you'll generate one below)
ssh-keygen -t rsa -b 4096 -f jenkins_agent_key -N ""This creates jenkins_agent_key (private) and jenkins_agent_key.pub (public).
Open docker-compose.yml and replace REPLACE_WITH_YOUR_PUBLIC_KEY with the contents
of jenkins_agent_key.pub.
docker compose up -d
docker compose psGet the initial admin password for Jenkins:
docker exec jenkins-controller cat /var/jenkins_home/secrets/initialAdminPasswordOpen http://localhost:8080, paste the password, install the suggested plugins,
and create your admin user.
- Manage Jenkins → Credentials → System → Global credentials → Add Credentials
- Kind: SSH Username with private key
- Username:
jenkins - Private key: paste the contents of
jenkins_agent_key(the private key file) - ID:
remote-agent-ssh-key
Manage Jenkins → Nodes → New Node
| Field | Value |
|---|---|
| Node name | remote-node-1 |
| Type | Permanent Agent |
| Remote root directory | /home/jenkins/agent |
| Labels | linux-remote |
| Launch method | Launch agents via SSH |
| Host | jenkins-agent (container name — resolvable on the shared Docker network) |
| Credentials | select remote-agent-ssh-key from Step 3 |
| Host Key Verification Strategy | Non verifying (fine for this local lab setup) |
Save. Jenkins will SSH into jenkins-agent and launch the remoting connection.
Check Manage Jenkins → Nodes — remote-node-1 should show as online (green).
By default Jenkins can run jobs directly on the controller, which is a security risk. To force ALL jobs onto agent nodes:
- Manage Jenkins → Nodes → built-in node (master)
- Configure → set Number of executors to
0
Now the controller only orchestrates; it can never execute untrusted build steps directly — a core DevOps/security best practice for Jenkins.
- New Item → Pipeline, name it
remote-node-demo - Under Pipeline, choose Pipeline script from SCM if using GitHub (point it at
this repo and
Jenkinsfile), or paste the contents ofJenkinsfiledirectly under Pipeline script for a quick local test. - Build Now
Open the build's Console Output. You should see:
hostname→remote-node-1(not the controller's hostname)whoami→jenkins- The archived artifact
build_output/result.txt
This is your proof the job executed remotely, not on the controller.
To demonstrate distributing different stages to different machines:
- Repeat Step 4 to register a second agent (you can reuse the same
jenkins-agentcontainer with a different label for a quick demo, or spin up a second container fromdocker-compose.ymlcopy-pasted with a new service name). - Label it
java-build. - Run the
Jenkinsfile.multi-nodepipeline and observe each stage's console output showing a differentNODE_NAME.
| Symptom | Fix |
|---|---|
| Agent shows offline | Check docker logs jenkins-agent; confirm the public key in docker-compose.yml matches your keypair |
| SSH connection refused | Confirm both containers are on the jenkins-net network: docker network inspect jenkins_jenkins-net |
| Job runs on controller instead of agent | Confirm agent { label 'linux-remote' } matches the exact label set on the node, and controller executors = 0 |
| "Host key verification failed" | Set Host Key Verification Strategy to "Non verifying" for this lab setup |
- Jenkins controller/agent (remoting) architecture
- Secure remote execution over SSH
- Distributing build load across machines via node labels
- Node isolation as a security hardening practice
- Multi-stage pipelines spanning multiple remote nodes
```bash
docker-compose up -d
```
This starts two containers: jenkins-controller and jenkins-agent, connected over the jenkins-net bridge network.
The agent node remote-node-1 registers with the controller and shows as online, in sync, with a healthy response time.
Running the remote-node-test pipeline confirms the build is dispatched to remote-node-1 — not the controller. The hostname and whoami steps in the console output verify this directly.
The Built-In Node (controller) is configured with 0 executors, so it is physically incapable of running any build itself. Every job is forced onto the labeled remote agent — a real-world security/scalability best practice.
All builds are distributed to the remote SSH agent, with the controller dedicated purely to orchestration.


