Skip to content

Commit dcaa2c2

Browse files
nihussmannschnatterer
authored andcommitted
exporting debug logs if integration test fails
1 parent 9f9b86f commit dcaa2c2

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Jenkinsfile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,16 @@ node('high-cpu') {
127127
script: "groovy ./scripts/e2e.groovy --url http://${k3dAddress}:9090 --user admin --password admin --writeFailedLog --fail --retry 2")
128128
}
129129

130-
if (ret > 0 ) {
130+
if (ret > 0) {
131131
if (fileExists('playground-logs-of-failed-jobs')) {
132132
archiveArtifacts artifacts: 'playground-logs-of-failed-jobs/*.log'
133133
}
134134
unstable "Integration tests failed, see logs appended to jobs and cluster status in logs"
135-
sh "docker exec k3d-${clusterName}-server-0 kubectl get all -A"
135+
136+
kubectlToFile(clusterName,"allPods.txt","get all -A")
137+
138+
printIntegrationTestLogs(clusterName,'app=scm-manager')
139+
printIntegrationTestLogs(clusterName,'app.kubernetes.io/name=jenkins')
136140
}
137141
}
138142

@@ -243,6 +247,20 @@ def trivy(String imageName, Map additionalTrivyConfig = [:]) {
243247
trivyConfig.additionalFlags += ' --java-db-repository public.ecr.aws/aquasecurity/trivy-java-db'
244248

245249
findVulnerabilitiesWithTrivy(trivyConfig)
250+
251+
}
252+
253+
def printIntegrationTestLogs(String clusterName, String appSelector, String namespace = 'default'){
254+
def filename=appSelector.split("=")
255+
256+
kubectlToFile(clusterName, "${filename[1]}.log", "logs -n ${namespace} -l ${appSelector} --tail=-1")
257+
kubectlToFile(clusterName, "${filename[1]}-previous.log", "logs -n ${namespace} -l ${appSelector} --tail=-1 -p")
258+
kubectlToFile(clusterName, "${filename[1]}-describe.txt", "describe pods -n ${namespace} -l ${appSelector}")
259+
}
260+
261+
void kubectlToFile(String clusterName, String filename, String command) {
262+
sh "docker exec k3d-${clusterName}-server-0 kubectl ${command} | tee ${filename}"
263+
archiveArtifacts artifacts: "${filename}", allowEmptyArchive: true
246264
}
247265

248266
def startK3d(clusterName) {

0 commit comments

Comments
 (0)