Print logs from PipelineRun pods when Tekton tests fail (#1019)

This commit is contained in:
Martin Gencur 2020-09-22 10:17:36 +02:00 committed by GitHub
parent 719269e891
commit f4e43c82d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -17,6 +17,7 @@
package e2e package e2e
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"testing" "testing"
@ -75,7 +76,11 @@ func TestTektonPipeline(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
err = waitForPipelineSuccess(kubectl) err = waitForPipelineSuccess(kubectl)
assert.NilError(t, err) if err != nil {
logs, logsErr := kubectl.Run("logs", "-l", "tekton.dev/pipeline=buildah-build-kn-create", "--all-containers", "--prefix=true")
assert.NilError(t, logsErr, "Unable to gather logs from pipeline pods")
t.Fatalf("PipelineRun failed with %v, printing logs from pipeline pods:\n%s", err, logs)
}
r := test.NewKnRunResultCollector(t, it) r := test.NewKnRunResultCollector(t, it)
@ -89,7 +94,14 @@ func TestTektonPipeline(t *testing.T) {
func waitForPipelineSuccess(k test.Kubectl) error { func waitForPipelineSuccess(k test.Kubectl) error {
return wait.PollImmediate(Interval, Timeout, func() (bool, error) { return wait.PollImmediate(Interval, Timeout, func() (bool, error) {
out, err := k.Run("get", "pipelinerun", "-o=jsonpath='{.items[0].status.conditions[?(@.type==\"Succeeded\")].status}'") out, err := k.Run("get", "pipelinerun", "-o=jsonpath='{.items[0].status.conditions[?(@.type==\"Succeeded\")].status}'")
return strings.Contains(out, "True"), err if err != nil {
return false, err
}
// Return early if the run failed.
if strings.Contains(out, "False") {
return false, errors.New("pipelinerun failure")
}
return strings.Contains(out, "True"), nil
}) })
} }