Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
This is a Node.js client for Jenkins.
These options will be passed along with any call, although only certain endpoints support them.
Initialize a new Jenkins client.
Options
require('form-data')
as value for this option)Usage
import Jenkins from "jenkins";
const jenkins = new Jenkins({
baseUrl: "http://user:pass@localhost:8080",
});
Get server information.
Usage
await jenkins.info();
Result
{
"assignedLabels": [{}],
"description": null,
"jobs": [
{
"color": "blue",
"name": "example",
"url": "http://localhost:8080/job/example/"
}
],
"mode": "NORMAL",
"nodeDescription": "the master Jenkins node",
"nodeName": "",
"numExecutors": 2,
"overallLoad": {},
"primaryView": {
"name": "All",
"url": "http://localhost:8080/"
},
"quietingDown": false,
"slaveAgentPort": 12345,
"unlabeledLoad": {},
"useCrumbs": false,
"useSecurity": false,
"views": [
{
"name": "All",
"url": "http://localhost:8080/"
}
]
}
Get build information.
Options
Usage
await jenkins.build.get("example", 1);
Result
{
"actions": [],
"buildable": true,
"builds": [
{
"number": 1,
"url": "http://localhost:8080/job/example/1/"
}
],
"color": "blue",
"concurrentBuild": false,
"description": "",
"displayName": "example",
"displayNameOrNull": null,
"downstreamProjects": [],
"firstBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"healthReport": [
{
"description": "Build stability: No recent builds failed.",
"iconUrl": "health-80plus.png",
"score": 100
}
],
"inQueue": false,
"keepDependencies": false,
"lastBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastCompletedBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastFailedBuild": null,
"lastStableBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastSuccessfulBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastUnstableBuild": null,
"lastUnsuccessfulBuild": null,
"name": "example",
"nextBuildNumber": 2,
"property": [],
"queueItem": null,
"scm": {},
"upstreamProjects": [],
"url": "http://localhost:8080/job/example/"
}
Get build log.
Options
Usage
await jenkins.build.log("example", 1);
Get build log stream.
Options
Usage
const log = jenkins.build.logStream("example", 1);
log.on("data", (text) => {
process.stdout.write(text);
});
log.on("error", (err) => {
console.log("error", err);
});
log.on("end", () => {
console.log("end");
});
Stop build.
Options
Usage
await jenkins.build.stop("example", 1);
Terminates build.
Options
Usage
await jenkins.build.term("example", 1);
Create credentials in a folder or system.
Options
manage
for system credentialsfolder
or system
Usage
await jenkins.credentials.create("folder", "store", "domain", "xml");
Check if credentials exist in a folder or system.
Options
manage
for system credentialsfolder
or system
Usage
await jenkins.credentials.exists("id", "folder", "store", "domain");
Get XML configuration of credentials.
Options
manage
for system credentialsfolder
or system
Usage
await jenkins.credentials.config("id", "folder", "store", "domain");
Update credentials.
Options
manage
for system credentialsfolder
or system
Usage
await jenkins.credentials.update("id", "folder", "store", "domain", "xml");
Delete credentials from folder or system.
Options
manage
for system credentialsfolder
or system
Usage
await jenkins.credentials.destroy("id", "folder", "store", "domain");
Get a list of credentials in a folder or system.
Options
manage
for system credentialsfolder
or system
Usage
await jenkins.credentials.list("folder", "store", "domain");
Trigger build.
Options
Usage
await jenkins.job.build("example");
await jenkins.job.build({
name: "example",
parameters: { name: "value" },
});
await jenkins.job.build({
name: "example",
parameters: { file: fs.createReadStream("test.txt") },
});
Get job XML configuration.
Options
Usage
await jenkins.job.config("example");
Update job XML configuration.
Options
Usage
await jenkins.job.config("example", xml);
Create job by copying existing job.
Options
Usage
await jenkins.job.copy("fromJob", "example");
Create job from scratch.
Options
Usage
await jenkins.job.create("example", xml);
Delete job.
Options
Usage
await jenkins.job.destroy("example");
Disable job.
Options
Usage
await jenkins.job.disable("example");
Enable job.
Options
Usage
await jenkins.job.enable("example");
Check job exists.
Options
Usage
await jenkins.job.exists("example");
Get job information.
Options
Usage
await jenkins.job.get("example");
Result
{
"actions": [],
"buildable": true,
"builds": [
{
"number": 1,
"url": "http://localhost:8080/job/example/1/"
}
],
"color": "blue",
"concurrentBuild": false,
"description": "",
"displayName": "example",
"displayNameOrNull": null,
"downstreamProjects": [],
"firstBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"healthReport": [
{
"description": "Build stability: No recent builds failed.",
"iconUrl": "health-80plus.png",
"score": 100
}
],
"inQueue": false,
"keepDependencies": false,
"lastBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastCompletedBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastFailedBuild": null,
"lastStableBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastSuccessfulBuild": {
"number": 1,
"url": "http://localhost:8080/job/example/1/"
},
"lastUnstableBuild": null,
"lastUnsuccessfulBuild": null,
"name": "example",
"nextBuildNumber": 2,
"property": [],
"queueItem": null,
"scm": {},
"upstreamProjects": [],
"url": "http://localhost:8080/job/example/"
}
List jobs.
Options
Usage
await jenkins.job.list();
Result
[
{
"color": "blue",
"name": "example",
"url": "http://localhost:8080/job/example/"
}
]
Get label information.
Options
Usage
await jenkins.label.get("master");
Result
{
"_class": "hudson.model.labels.LabelAtom",
"actions": [],
"busyExecutors": 0,
"clouds": [],
"description": null,
"idleExecutors": 2,
"loadStatistics": {
"_class": "hudson.model.Label$1"
},
"name": "master",
"nodes": [
{
"_class": "hudson.model.Hudson",
"nodeName": ""
}
],
"offline": false,
"tiedJobs": [],
"totalExecutors": 2,
"propertiesList": []
}
Get node XML configuration.
Options
Usage
await jenkins.node.config("example");
Create node.
Options
Usage
await jenkins.node.create("node-name");
Delete node.
Options
Usage
await jenkins.node.destroy("node-name");
Disconnect node.
Options
Usage
await jenkins.node.disconnect("node-name", "no longer used");
Disable node.
Options
Usage
await jenkins.node.disable("node-name", "network failure");
Enable node.
Options
Usage
await jenkins.node.enable("node-name");
Check node exists.
Options
Usage
await jenkins.node.exists("node-name");
Get node information.
Options
Usage
await jenkins.node.get("node-name");
Result
{
"actions": [],
"displayName": "node-name",
"executors": [{}, {}],
"icon": "computer-x.png",
"idle": true,
"jnlpAgent": true,
"launchSupported": false,
"loadStatistics": {},
"manualLaunchAllowed": true,
"monitorData": {
"hudson.node_monitors.ArchitectureMonitor": null,
"hudson.node_monitors.ClockMonitor": null,
"hudson.node_monitors.DiskSpaceMonitor": null,
"hudson.node_monitors.ResponseTimeMonitor": {
"average": 5000
},
"hudson.node_monitors.SwapSpaceMonitor": null,
"hudson.node_monitors.TemporarySpaceMonitor": null
},
"numExecutors": 2,
"offline": true,
"offlineCause": null,
"offlineCauseReason": "",
"oneOffExecutors": [],
"temporarilyOffline": false
}
List all nodes.
Options
Usage
await jenkins.node.list();
Result
{
"busyExecutors": 0,
"computer": [
{
"actions": [],
"displayName": "master",
"executors": [{}, {}],
"icon": "computer.png",
"idle": true,
"jnlpAgent": false,
"launchSupported": true,
"loadStatistics": {},
"manualLaunchAllowed": true,
"monitorData": {
"hudson.node_monitors.ArchitectureMonitor": "Linux (amd64)",
"hudson.node_monitors.ClockMonitor": {
"diff": 0
},
"hudson.node_monitors.DiskSpaceMonitor": {
"path": "/var/lib/jenkins",
"size": 77620142080
},
"hudson.node_monitors.ResponseTimeMonitor": {
"average": 0
},
"hudson.node_monitors.SwapSpaceMonitor": {
"availablePhysicalMemory": 22761472,
"availableSwapSpace": 794497024,
"totalPhysicalMemory": 515358720,
"totalSwapSpace": 805302272
},
"hudson.node_monitors.TemporarySpaceMonitor": {
"path": "/tmp",
"size": 77620142080
}
},
"numExecutors": 2,
"offline": false,
"offlineCause": null,
"offlineCauseReason": "",
"oneOffExecutors": [],
"temporarilyOffline": false
},
{
"actions": [],
"displayName": "node-name",
"executors": [{}, {}],
"icon": "computer-x.png",
"idle": true,
"jnlpAgent": true,
"launchSupported": false,
"loadStatistics": {},
"manualLaunchAllowed": true,
"monitorData": {
"hudson.node_monitors.ArchitectureMonitor": null,
"hudson.node_monitors.ClockMonitor": null,
"hudson.node_monitors.DiskSpaceMonitor": null,
"hudson.node_monitors.ResponseTimeMonitor": {
"average": 5000
},
"hudson.node_monitors.SwapSpaceMonitor": null,
"hudson.node_monitors.TemporarySpaceMonitor": null
},
"numExecutors": 2,
"offline": true,
"offlineCause": null,
"offlineCauseReason": "",
"oneOffExecutors": [],
"temporarilyOffline": false
}
],
"displayName": "nodes",
"totalExecutors": 2
}
List plugins (note: depth defaults to 1).
Usage
await jenkins.plugin.list();
Result
[
{
"active": true,
"backupVersion": null,
"bundled": false,
"deleted": false,
"dependencies": [{}, {}, {}, {}, {}, {}, {}, {}],
"downgradable": false,
"enabled": true,
"hasUpdate": false,
"longName": "Email Extension Plugin",
"pinned": false,
"shortName": "email-ext",
"supportsDynamicLoad": "MAYBE",
"url": "http://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin",
"version": "2.53"
}
]
List queues.
Usage
await jenkins.queue.list();
Result
{
"items": [
{
"actions": [
{
"causes": [
{
"shortDescription": "Started by user anonymous",
"userId": null,
"userName": "anonymous"
}
]
}
],
"blocked": true,
"buildable": false,
"buildableStartMilliseconds": 1389418977387,
"id": 20,
"inQueueSince": 1389418977358,
"params": "",
"stuck": false,
"task": {
"color": "blue_anime",
"name": "example",
"url": "http://localhost:8080/job/example/"
},
"url": "queue/item/20/",
"why": "Build #2 is already in progress (ETA:N/A)"
}
]
}
Lookup a queue item.
Options
Usage
await jenkins.queue.item(130);
Result
{
"actions": [
{
"causes": [
{
"shortDescription": "Started by user anonymous",
"userId": null,
"userName": "anonymous"
}
]
}
],
"blocked": false,
"buildable": false,
"id": 130,
"inQueueSince": 1406363479853,
"params": "",
"stuck": false,
"task": {
"name": "test-job-b7ef0845-6515-444c-96a1-d2266d5e0f18",
"url": "http://localhost:8080/job/test-job-b7ef0845-6515-444c-96a1-d2266d5e0f18/",
"color": "blue"
},
"url": "queue/item/130/",
"why": null,
"executable": {
"number": 28,
"url": "http://localhost:8080/job/test-job-b7ef0845-6515-444c-96a1-d2266d5e0f18/28/"
}
}
Cancel build in queue.
Options
Usage
await jenkins.queue.cancel(23);
Get view XML configuration.
Options
Usage
await jenkins.view.config("example");
Update view XML configuration.
Options
Usage
await jenkins.view.config("example", xml);
Create view.
Options
Usage
await jenkins.view.create("example", "list");
Delete view.
Options
Usage
await jenkins.view.destroy("example");
Check view exists.
Options
Usage
await jenkins.view.exists("example");
Get view information.
Options
Usage
await jenkins.view.get("example");
Result
{
"description": null,
"jobs": [
{
"name": "test",
"url": "http://localhost:8080/job/example/",
"color": "blue"
}
],
"name": "example",
"property": [],
"url": "http://localhost:8080/view/example/"
}
List all views.
Usage
await jenkins.view.list();
Result
{
"views": [
{
"url": "http://localhost:8080/",
"name": "All"
},
{
"url": "http://localhost:8080/view/example/",
"name": "Test"
}
],
"useSecurity": false,
"useCrumbs": false,
"unlabeledLoad": {},
"slaveAgentPort": 0,
"quietingDown": false,
"primaryView": {
"url": "http://localhost:8080/",
"name": "All"
},
"assignedLabels": [{}],
"mode": "NORMAL",
"nodeDescription": "the master Jenkins node",
"nodeName": "",
"numExecutors": 2,
"description": null,
"jobs": [
{
"color": "notbuilt",
"url": "http://localhost:8080/job/example/",
"name": "test"
}
],
"overallLoad": {}
}
Add job to view.
Options
Usage
await jenkins.view.add("example", "jobExample");
Remove job from view.
Options
Usage
await jenkins.view.remove("example", "jobExample");
Run unit tests
$ npm test
Run acceptance tests
$ docker compose -f test/compose.yml up -d --build
$ npm run acceptance
$ docker compose -f test/compose.yml down
This work is licensed under the MIT License (see the LICENSE file).
python-jenkins (BSD License, see NOTES) was used as a reference when implementing this client and its create/reconfigure job XML was used in the tests.
FAQs
Jenkins client
The npm package jenkins receives a total of 19,723 weekly downloads. As such, jenkins popularity was classified as popular.
We found that jenkins demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.