Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save suya55/06f9ed70d75767218284bf27fbf34ec6 to your computer and use it in GitHub Desktop.
Save suya55/06f9ed70d75767218284bf27fbf34ec6 to your computer and use it in GitHub Desktop.

Revisions

  1. @rhuss rhuss revised this gist Jul 16, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions execute_groovy_jenkins_sample.groovy
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,8 @@ def exec(cmd) {
    [
    "mkdir /tmp/,x",
    "echo FROM busybox > /tmp/,x/Dockerfile",
    "DOCKER_HOST=tcp://localhost:2375 docker build -t fabric8/test:1.0 /tmp/,x",
    "DOCKER_HOST=tcp://localhost:2375 docker push --force=true fabric8/test:1.0",
    "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"
  2. @rhuss rhuss renamed this gist Jul 16, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. @rhuss rhuss renamed this gist Jul 16, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions gistfile1.txt → execute.groovy
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,7 @@ def exec(cmd) {
    .directory(new File("/tmp"))
    .redirectErrorStream(true)
    .start()
    process.outputStream.close()
    process.inputStream.eachLine {println it}
    process.waitFor();
    return process.exitValue()
    @@ -12,8 +13,8 @@ def exec(cmd) {
    [
    "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 test/test:1.0",
    "DOCKER_HOST=tcp://localhost:2375 docker build -t fabric8/test:1.0 /tmp/,x",
    "DOCKER_HOST=tcp://localhost:2375 docker push --force=true fabric8/test:1.0",
    "rm /tmp/,x/Dockerfile",
    "rmdir /tmp/,x",
    "DOCKER_HOST=tcp://localhost:2375 docker rmi test/test:1.0"
  4. @rhuss rhuss revised this gist Jul 16, 2015. 1 changed file with 5 additions and 13 deletions.
    18 changes: 5 additions & 13 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    private def executeOnShell(String command) {
    println command
    def process = new ProcessBuilder(addShellPrefix(command))
    def exec(cmd) {
    println cmd
    def process = new ProcessBuilder([ "sh", "-c", cmd])
    .directory(new File("/tmp"))
    .redirectErrorStream(true)
    .start()
    @@ -9,14 +9,6 @@ private def executeOnShell(String command) {
    return process.exitValue()
    }

    private def addShellPrefix(String command) {
    commandArray = new String[3]
    commandArray[0] = "sh"
    commandArray[1] = "-c"
    commandArray[2] = command
    return commandArray
    }

    [
    "mkdir /tmp/,x",
    "echo FROM busybox > /tmp/,x/Dockerfile",
    @@ -26,5 +18,5 @@ private def addShellPrefix(String command) {
    "rmdir /tmp/,x",
    "DOCKER_HOST=tcp://localhost:2375 docker rmi test/test:1.0"
    ].each {
    executeOnShell(it)
    }
    exec(it)
    }
  5. @rhuss rhuss created this gist Jul 16, 2015.
    30 changes: 30 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    private def executeOnShell(String command) {
    println command
    def process = new ProcessBuilder(addShellPrefix(command))
    .directory(new File("/tmp"))
    .redirectErrorStream(true)
    .start()
    process.inputStream.eachLine {println it}
    process.waitFor();
    return process.exitValue()
    }

    private def addShellPrefix(String command) {
    commandArray = new String[3]
    commandArray[0] = "sh"
    commandArray[1] = "-c"
    commandArray[2] = command
    return commandArray
    }

    [
    "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 test/test:1.0",
    "rm /tmp/,x/Dockerfile",
    "rmdir /tmp/,x",
    "DOCKER_HOST=tcp://localhost:2375 docker rmi test/test:1.0"
    ].each {
    executeOnShell(it)
    }