Skip to content

Instantly share code, notes, and snippets.

@swsnr
Last active September 20, 2019 08:08
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/4c11a5e3ce8912296bbf94897ea28c17 to your computer and use it in GitHub Desktop.
Save swsnr/4c11a5e3ce8912296bbf94897ea28c17 to your computer and use it in GitHub Desktop.
SBT Jenkins Pipeline Step
#!/usr/bin/groovy
/**
* Run SBT via sh with the given arguments.
*
* Injects a file pointed to by $NEXUS_CREDENTIALS env var for publishing credentials.
* Use the Credentials Jenkins plugin to manage these credentials in Jenkins and inject
* them into a build.
*
* @param sbtArgs Arguments for SBT
* @return
*/
def call(String sbtArgs) {
// Extract the launcher to file system
def sbt = "${pwd tmp: true}/sbt"
// A copy of <https://github.com/paulp/sbt-extras/blob/master/sbt> included as library resource
def launcher = libraryResource 'com/acme/sbt-extras/sbt'
writeFile file: sbt, text: launcher
def inputrc = "${pwd tmp: true}/inputrc"
// Get hold of Nexus credentials
withCredentials([file(credentialsId: 'sbt-nexus-credentials', variable: 'NEXUS_CREDENTIALS')]) {
def defaultArgs = [
// Make jline use an empty inputrc to fix "unable to bind key"
// issues in SBT
"'-Djline.inputrc=${inputrc}'",
// Disable formatting, doesn't look well in Jenkins build console
'-Dsbt.log.noformat=true',
// Credentials for booting SBT from our nexus (note: we deliberately quote here because
// NEXUS_CREDENTIALS is an environment variable not a groovy variable)…
'"-Dsbt.boot.credentials=${NEXUS_CREDENTIALS}"',
// …and for SBT the actual SBT build
'\'set Global / credentials += Credentials(file(sys.env("NEXUS_CREDENTIALS")))\'',
]
sh label: 'sbt', script: "bash ${sbt} ${defaultArgs.join(' ')} ${sbtArgs}"
}
}
@swsnr
Copy link
Author

swsnr commented Sep 19, 2019 via email

@muuki88
Copy link

muuki88 commented Sep 20, 2019

Saw that too 🤗 and deleted my command instantly 😹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment