-
-
Save suya55/06f9ed70d75767218284bf27fbf34ec6 to your computer and use it in GitHub Desktop.
How to execute some shell scripting on Groovy with environment variables and redirection
This file contains 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
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