Last active
September 1, 2017 13:00
-
-
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.
This file contains hidden or 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add compatibility with Windows