Skip to content

Instantly share code, notes, and snippets.

@igorescobar
Last active January 19, 2017 02:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorescobar/d214ee6d1c2032ebc5a3 to your computer and use it in GitHub Desktop.
Save igorescobar/d214ee6d1c2032ebc5a3 to your computer and use it in GitHub Desktop.
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