Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Small script to convert an Build Pipeline View to a Markdown table
/*
Instructions:
1 - Open the Jenkins Pipeline View with your browser
2 - Open the console and execute the following code
3 - Copy the output and paste into your README.md
Your github README.md will never be the same ;o)
Example:
| CI | Build Pipeline: Project Name |
|-------------|:------------------------------:|
| $build_name | $badge_button |
| $build_name | $badge_button |
| $build_name | $badge_button |
| $build_name | $badge_button |
| $build_name | $badge_button |
| $build_name | $badge_button |
*/
var pipelineTitle = jQuery('#build-pipeline-plugin-content h1').text().trim(),
pipelineBasePath = window.location.protocol + "//" + window.location.host,
pipelineApiUrl = window.location.href + '/api/json',
tableLineTemplate = "|$jobName|[![$jobName]($pipelineBasePath/buildStatus/icon?job=$jobName/)]($jobUrl)|",
table = [
"| CI | $pipelineTitle |",
"|------------|:---------------:|"
];
jQuery.getJSON(pipelineApiUrl, function(data){
var jobName, jobUrl;
jQuery.each(data.jobs, function(i, job){
jobName = job.name;
jobUrl = job.url;
table.push(
tableLineTemplate.replace(/\$jobName/g, jobName)
.replace(/\$jobUrl/g, jobUrl)
.replace(/\$pipelineBasePath/g, pipelineBasePath)
)
});
document.writeln(table.join('<br/>\n').replace(/\$pipelineTitle/g, pipelineTitle));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment