Skip to content

Instantly share code, notes, and snippets.

@kocubinski
Last active December 4, 2018 03:42
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 kocubinski/96805b269f48c80c95d39a1bead7ed50 to your computer and use it in GitHub Desktop.
Save kocubinski/96805b269f48c80c95d39a1bead7ed50 to your computer and use it in GitHub Desktop.
Return the host's path of a Jenkins WORKSPACE running a docker container.
import groovy.json.JsonSlurper;
def call(String workspace) {
def p = ['/bin/bash', '-c', '''
docker ps --no-trunc --all \
| grep `cat /etc/hostname` \
| grep jenkins.sh \
| awk '{print $1}' \
| xargs docker inspect
'''].execute()
p.waitFor();
def o = new JsonSlurper().parseText(p.text)
def source = o[0].Mounts.find { it.Destination == "/var/jenkins_home" }.Source
return workspace.replace("/var/jenkins_home", source)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment