Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created March 16, 2018 13:18
Show Gist options
  • Save m-x-k/53b17daaa094791da2f8963a9763dfab to your computer and use it in GitHub Desktop.
Save m-x-k/53b17daaa094791da2f8963a9763dfab to your computer and use it in GitHub Desktop.
Jenkins Pipeline To Archive Docker Data For All Nodes
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