@@ -8,7 +8,7 @@ pipeline {
88 }
99
1010 options {
11- buildDiscarder(logRotator(numToKeepStr : ' 5 ' ))
11+ buildDiscarder(logRotator(numToKeepStr : ' 20 ' ))
1212 timestamps()
1313 timeout(time : 120 , unit : ' MINUTES' )
1414 }
@@ -51,8 +51,12 @@ pipeline {
5151 }}
5252 steps {
5353 sh ' mvn -B clean test'
54- junit testResults : ' **/target/surefire-reports/TEST-*.xml'
55- archiveArtifacts artifacts : " **/target/site/jacoco/**"
54+ }
55+ post {
56+ always {
57+ junit testResults : ' **/target/surefire-reports/TEST-*.xml'
58+ archiveArtifacts artifacts : " **/target/site/jacoco/**"
59+ }
5660 }
5761 }
5862
@@ -106,16 +110,56 @@ pipeline {
106110 profiles = [params. chooseProfile]
107111 }
108112
109- def withK3dCluster = { body ->
113+ def dumpKubernetesDebugInfo = { profile ->
114+ def dumpDir = " target/k8s-debug/${ profile} "
115+
116+ docker. image(" ${ env.GOLANG_IMAGE} " ). inside(env. INTEGRATION_TEST_DOCKER_ARGS ) {
117+ sh(script : """
118+ set +e
119+ apk add --no-cache kubectl
120+ mkdir -p '${ dumpDir} '
121+ export KUBECONFIG='${ env.WORKSPACE} /.kubeconfig.yaml'
122+
123+ kubectl cluster-info > '${ dumpDir} /cluster-info.txt' 2>&1
124+ kubectl get nodes -o wide > '${ dumpDir} /nodes.txt' 2>&1
125+ kubectl get namespaces -o wide > '${ dumpDir} /namespaces.txt' 2>&1
126+ kubectl get pods -A -o wide > '${ dumpDir} /pods.txt' 2>&1
127+ kubectl get events -A --sort-by=.lastTimestamp > '${ dumpDir} /events.txt' 2>&1
128+ kubectl get pvc,pv -A -o wide > '${ dumpDir} /volumes.txt' 2>&1
129+ kubectl get ingress -A -o wide > '${ dumpDir} /ingress.txt' 2>&1
130+ kubectl describe all -A > '${ dumpDir} /describe-all.txt' 2>&1
131+
132+ : > '${ dumpDir} /container-logs.txt'
133+ kubectl get pods -A --no-headers \\
134+ -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name |
135+ while read -r namespace pod; do
136+ echo "===== \$ {namespace}/\$ {pod} current =====" >> '${ dumpDir} /container-logs.txt'
137+ kubectl logs -n "\$ {namespace}" "\$ {pod}" --all-containers=true --tail=200 --prefix=true >> '${ dumpDir} /container-logs.txt' 2>&1
138+
139+ echo >> '${ dumpDir} /container-logs.txt'
140+ echo "===== \$ {namespace}/\$ {pod} previous =====" >> '${ dumpDir} /container-logs.txt'
141+ kubectl logs -n "\$ {namespace}" "\$ {pod}" --all-containers=true --previous --tail=200 --prefix=true >> '${ dumpDir} /container-logs.txt' 2>&1
142+ echo >> '${ dumpDir} /container-logs.txt'
143+ done
144+ """ , returnStatus : true )
145+ }
146+
147+ archiveArtifacts artifacts : " ${ dumpDir} /**" , allowEmptyArchive : true
148+ }
149+
150+ def withK3dCluster = { profile , body ->
110151 try {
111152 sh " yes | KUBECONFIG=${ env.WORKSPACE} /.kubeconfig.yaml ./scripts/init-cluster.sh --cluster-name=${ env.K3D_CLUSTER_NAME} "
112153 body()
154+ } catch (Throwable t) {
155+ dumpKubernetesDebugInfo(profile)
156+ throw t
113157 } finally {
114158 sh " KUBECONFIG=${ env.WORKSPACE} /.kubeconfig.yaml $HOME /.local/bin/k3d cluster delete ${ env.K3D_CLUSTER_NAME} "
115159 }}
116160
117161 profiles. each { profile ->
118- withK3dCluster {
162+ withK3dCluster(profile) {
119163
120164 if (profile. startsWith(' operator' )) {
121165 docker. image(" ${ env.GOLANG_IMAGE} " ). inside(env. INTEGRATION_TEST_DOCKER_ARGS ) {
@@ -130,11 +174,16 @@ pipeline {
130174 sh " mvn -B failsafe:integration-test failsafe:verify -Dmicronaut.environments=${ profile} -Dsurefire.reportNameSuffix=${ profile} && chown $BUILD_USER :$BUILD_GROUP ./* -R"
131175 }
132176 }
133- junit testResults : " **/target/failsafe-reports/TEST-*${ profile} .xml" ,
134- allowEmptyResults : true
177+
135178 }
136179 }
137180 }
181+ post {
182+ always {
183+ junit testResults : " **/target/failsafe-reports/TEST-*.xml" ,
184+ allowEmptyResults : true
185+ }
186+ }
138187 }
139188 }
140189 }
@@ -160,7 +209,6 @@ pipeline {
160209 currentBuild. description = " Image: ${ env.FULL_IMAGE_TAG} "
161210 image. push()
162211
163- if (params. forcePushImage || env. BRANCH_NAME == ' develop' ) { image. push(env. BRANCH_NAME ) }
164212 if (env. TAG_NAME ) {
165213 image. push(' latest' )
166214 image. push(env. TAG_NAME )
@@ -187,4 +235,4 @@ pipeline {
187235 )
188236 }
189237 }
190- }
238+ }
0 commit comments