Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fetches names and versions of all dependencies of particular Jenkins Plugin. Useful for automatic plugin installations via DevOps tools like Ansible, when all required plugin dependencies have to be manually installed via Jenkins CLI
// This is app.js file
var request = require("request"),
cheerio = require("cheerio"),
_ = require("lodash");
var foundDependencies = [];
function findDependencies(error, response, body, currentDependency) {
if (error) {
console.log("We’ve encountered an error: " + error);
return;
}
var $ = cheerio.load(body);
if (currentDependency) {
var latestVersion = $(".confluenceTd a").filter((index, dependency) =>_.contains(dependency.attribs.href, "latest"))[0];
currentDependency.version = latestVersion.children[0].data;
console.log(currentDependency.name + ", " + currentDependency.version);
}
var newDependencies = $(".confluenceTd a")
.map((index, dependency) => ({
href: dependency.attribs.href,
name: dependency.children[0].data,
optional: dependency.next && _.contains(dependency.next.data, "optional")
}))
.filter((index, dependency) =>_.contains(dependency.href, "display/JENKINS") && dependency.name && !dependency.optional)
.filter((index, dependency) => !_.contains(foundDependencies.map(dep => dep.name), dependency.name));
newDependencies.each((index, dependency) => {
foundDependencies.push(dependency);
request(dependency.href, (error, response, body) => {
findDependencies(error, response, body, dependency);
});
});
}
request("https://wiki.jenkins-ci.org/display/JENKINS/SSH+Agent+Plugin", findDependencies);
ssh-credentials, 1.11
workflow-step-api, 1.12
credentials, 1.24
workflow-scm-step, 1.12
workflow-cps, 1.12
workflow-durable-task-step, 1.12
workflow-support, 1.12
workflow-api, 1.12
workflow-job, 1.12
workflow-basic-steps, 1.12
workflow-cps-global-lib, 1.12
To run (Node.js required):
npm install
node --harmony app.js
{
"name": "jenkins-dependencies",
"version": "1.0.0",
"main": "app.js",
"dependencies": {
"cheerio": "^0.19.0",
"lodash": "^3.10.1",
"request": "^2.67.0"
}
}
@Eldadc
Copy link

Eldadc commented Sep 9, 2017

Hi,
Is it possible to run it on a jenkins to check what is missing or what should be update s.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment