Last active
January 19, 2017 02:25
-
-
Save igorescobar/d214ee6d1c2032ebc5a3 to your computer and use it in GitHub Desktop.
Small script to convert an Build Pipeline View to a Markdown table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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