Skip to main content
This article shows a concise scripted Jenkins pipeline that runs entirely on a dedicated static agent. By specifying the agent label at the top-level node(...), every stage executes on that agent instead of the controller (master) node. We already have an agent configured with the label ubuntu-docker-jdk17-node20 (Ubuntu + Docker + JDK 17 + Node 20). We’ll use that label to ensure the pipeline uses the static agent.
A Jenkins node page for "Agent ubuntu-agent" showing the node is connected with monitoring data (Architecture: Linux amd64, Free Disk Space: 72.87 GiB, Free Swap: 0 B, Response Time: 78ms). The left sidebar shows Jenkins menu options and a highlighted label "ubuntu-docker-jdk17-node20."
Wrap the label in single quotes when specifying the node: node('ubuntu-docker-jdk17-node20').
Below is a compact, production-oriented example Jenkinsfile that:
  • pins the pipeline to the static agent at the node level,
  • checks out source code,
  • uses a configured Node.js tool installation (updates PATH),
  • and runs a Unit Testing stage that injects MongoDB credentials with withCredentials.
Stages and common commands
Never hard-code secrets in your Jenkinsfile. Store credentials in the Jenkins Credentials store and reference them by credential ID (for example mongo-credentials). withCredentials masks/hides sensitive values in the console output.
Notes on credentials and environment variables:
  • withCredentials injects MONGO_USERNAME and MONGO_PASSWORD into the environment for the duration of the block.
  • If your tests need a MONGO_URI, provide it either as:
    • a global environment variable in Jenkins (Pipeline environment/global config), or
    • build it dynamically inside the pipeline and export via withEnv.
  • Use the Jenkins UI to create and manage credentials. Reference them by the returned credential ID in your pipeline.
Example trimmed console output from a successful run:
What happened
  • Because the node label was provided at the top level (node('ubuntu-docker-jdk17-node20')), the entire scripted pipeline executed on that static agent.
  • The tool step installed/mapped the Node.js tool and withEnv updated PATH so node/npm were available.
  • withCredentials injected MONGO_USERNAME and MONGO_PASSWORD for the test run; the tests connected to MongoDB and completed successfully.
Links and references

Watch Video