Last active
December 4, 2018 03:42
-
-
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.
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
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