In this guide, we’ll transform the existing Solar System PipelineDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Jenkinsfile from using agent any to leveraging a Kubernetes agent. By externalizing Pod definitions into a YAML manifest and targeting specific Node.js containers for build stages, we achieve more consistent, scalable CI/CD workflows.
Original Jenkinsfile Overview
The current pipeline uses a generic agent and defines global tools, environment variables, and stages:| Feature | Description |
|---|---|
| agent any | Runs on any available Jenkins node |
| environment variables | Database URIs, credentials, and SonarQube scanner path |
| stages | Dependency install, tests, Docker build, security scans |
Defining the Kubernetes Pod Manifest
Create ak8s-agent.yaml at your repo root to specify two Node.js containers:
node-18 and node-19 containers that Jenkins will schedule within a single Pod.
Ensure the Kubernetes plugin is installed in Jenkins and your Kubernetes cloud configuration (
dasher-prod-k8s-us-east) is active before running the refactored pipeline.Refactoring Jenkinsfile to Use Kubernetes Agent
Replace the top-levelagent any with the kubernetes agent block, referencing the YAML manifest and defaulting to node-18:

Stage-Level Container Configuration
We’ll run Node.js–specific stages innode-18, while Docker build and security scans fall back to agent any. Here’s the updated stage block:
| Stage | Container | Agent |
|---|---|---|
| Installing Dependencies | node-18 | kubernetes |
| Dependency Scanning | node-18 | kubernetes |
| Unit Testing | node-18 | kubernetes |
| Code Coverage | node-18 | kubernetes |
| Build Docker Image | default host | any |
| Trivy Vulnerability | default host | any |

Running and Monitoring the Refactored Pipeline
Commit your changes and push to trigger the pipeline. You can monitor status and logs in Blue Ocean:

All Node.js stages share an
emptyDir volume by default, so dependencies installed in one stage persist for subsequent stages within the same Pod.Links and References
- Jenkins Kubernetes Plugin
- Blue Ocean Documentation
- Kubernetes Pod Spec
- Trivy Security Scanner
- Jenkins Pipeline Syntax