Skip to content

Instantly share code, notes, and snippets.

@mig82
Last active September 1, 2017 13:00
Show Gist options
  • Save mig82/474598f65e31f6a6e2d5994645593e3b to your computer and use it in GitHub Desktop.
Save mig82/474598f65e31f6a6e2d5994645593e3b to your computer and use it in GitHub Desktop.
A Groovy library that can be used in a Jenkinsfile to call a shell command and retrieve the output from it.
import java.util.UUID
def command(command) {
def uuid = UUID.randomUUID()
def filename = "cmd-${uuid}"
echo(filename)
def cmd = "${command} > ${filename}"
isUnix()?sh(cmd):bat(cmd)
def result = readFile(filename).trim()
isUnix()?sh("rm ${filename}"):bat("del ${filename}")
return result
}
@mig82
Copy link
Author

mig82 commented Sep 1, 2017

Add compatibility with Windows

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