Last active
August 29, 2019 06:49
-
-
Save swsnr/6d4a887429f45bd0b80ecceae117b555 to your computer and use it in GitHub Desktop.
showSbtDependencies Jenkins Pipeline Step
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
#!/usr/bin/groovy | |
/** | |
* Extract project versions from all SBT POMs and publish them as summary badge. | |
* | |
* Requires Badge and Pipeline Utility Step plugins. | |
*/ | |
def call() { | |
// Clear out old badge if any | |
removeBadges id: 'sbt-dependencies' | |
// Collect dependencies | |
def poms = findFiles glob: '**/target/scala-*/*.pom' | |
def dependencies = poms.collect { file -> | |
def pom = readMavenPom file: file.path | |
// We do not use artifactId here because it already includes the scala version | |
[group: pom.groupId, name: pom.name.toLowerCase(), version: pom.version] | |
} | |
// Render badge | |
if (!dependencies.isEmpty()) { | |
def badge = createSummary icon: 'package.png', id: 'sbt-dependencies', | |
text: '<p>SBT dependencies published by this build:</p>\n' | |
badge.appendText('<ul>\n') | |
for (dependency in dependencies) { | |
badge.appendText("<li><code>\"${dependency.group}\" %% \"${dependency.name}\" % \"${dependency.version}\"</code></li>\n") | |
} | |
badge.appendText('</ul>\n') | |
} | |
// Make collected dependencies available to caller | |
return dependencies | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment