Skip to content

Instantly share code, notes, and snippets.

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 wayneseymour/1551f728cf6e3b10ea2cf018ceb580a7 to your computer and use it in GitHub Desktop.
Save wayneseymour/1551f728cf6e3b10ea2cf018ceb580a7 to your computer and use it in GitHub Desktop.
How to execute some shell scripting on Groovy with environment variables and redirection
def exec(cmd) {
println cmd
def process = new ProcessBuilder([ "sh", "-c", cmd])
.directory(new File("/tmp"))
.redirectErrorStream(true)
.start()
process.outputStream.close()
process.inputStream.eachLine {println it}
process.waitFor();
return process.exitValue()
}
[
"mkdir /tmp/,x",
"echo FROM busybox > /tmp/,x/Dockerfile",
"DOCKER_HOST=tcp://localhost:2375 docker build -t test/test:1.0 /tmp/,x",
"DOCKER_HOST=tcp://localhost:2375 docker push --force=true test/test:1.0",
"rm /tmp/,x/Dockerfile",
"rmdir /tmp/,x",
"DOCKER_HOST=tcp://localhost:2375 docker rmi test/test:1.0"
].each {
exec(it)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment