Last active
August 12, 2020 19:09
-
-
Save rhuss/cefa5f944931d0b313e2 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
`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()
}
exec("cd ~/Documents/ocbc/knowledgebase.local/")
exec("pwd")`
Error:
pwd
/private/tmp
Expected : pwd value should be this directory passed in parameter.