Created
March 16, 2018 13:18
-
-
Save m-x-k/53b17daaa094791da2f8963a9763dfab to your computer and use it in GitHub Desktop.
Jenkins Pipeline To Archive Docker Data For All Nodes
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 nodeName | |
stage("ArchiveDockerData") { | |
def nodeNameList = nodeNames() | |
for (String n : nodeNameList) { | |
nodeName = n | |
echo "Docker info for ${nodeName}" | |
timeout(time: 5, unit: 'SECONDS') { | |
try { | |
node(nodeName) { | |
result = sh(returnStdout: true, script: "docker ps -a --format '{{json .Names}},{{json .Image}},{{json .Status}},{{json .Ports}},{{json .CreatedAt}}'").trim() | |
writeFile file: "${nodeName}.csv", text:"$result" | |
archiveArtifacts "${nodeName}.csv" | |
} | |
} catch (err) { | |
echo "Ignored" | |
} | |
} | |
} | |
} | |
@NonCPS | |
def nodeNames() { | |
return jenkins.model.Jenkins.instance.nodes.collect { node -> node.name } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment