Skip to content

Instantly share code, notes, and snippets.

@swsnr
Last active August 29, 2019 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swsnr/6d4a887429f45bd0b80ecceae117b555 to your computer and use it in GitHub Desktop.
Save swsnr/6d4a887429f45bd0b80ecceae117b555 to your computer and use it in GitHub Desktop.
showSbtDependencies Jenkins Pipeline Step
#!/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