diff --git a/pkg/clients/tekton/pipelineruns.go b/pkg/clients/tekton/pipelineruns.go index 618459c96..2a10e020e 100644 --- a/pkg/clients/tekton/pipelineruns.go +++ b/pkg/clients/tekton/pipelineruns.go @@ -239,7 +239,7 @@ func (t *TektonController) StorePipelineRun(prefix string, pipelineRun *pipeline pipelineRunYaml, err := yaml.Marshal(pipelineRun) if err != nil { - return err + g.GinkgoWriter.Printf("failed to store pipelineRun %s:%s: %s\n", pipelineRun.GetNamespace(), pipelineRun.GetName(), err.Error()) } artifacts["pipelineRun-"+pipelineRun.Name+".yaml"] = pipelineRunYaml diff --git a/pkg/clients/tekton/taskruns.go b/pkg/clients/tekton/taskruns.go index 4f677d649..aff089993 100644 --- a/pkg/clients/tekton/taskruns.go +++ b/pkg/clients/tekton/taskruns.go @@ -6,11 +6,13 @@ import ( "strings" "time" + "github.com/konflux-ci/e2e-tests/pkg/logs" "github.com/konflux-ci/e2e-tests/pkg/utils" g "github.com/onsi/ginkgo/v2" "github.com/tektoncd/pipeline/pkg/apis/pipeline/pod" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" + "sigs.k8s.io/yaml" pointer "k8s.io/utils/ptr" pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" @@ -91,6 +93,37 @@ func (t *TektonController) GetTaskRun(name, namespace string) (*pipeline.TaskRun return &taskRun, nil } +// StoreTaskRun stores a given TaskRun as an artifact. +func (t *TektonController) StoreTaskRun(prefix string, taskRun *pipeline.TaskRun) error { + artifacts := make(map[string][]byte) + + taskRunYaml, err := yaml.Marshal(taskRun) + if err != nil { + g.GinkgoWriter.Printf("failed to store taskRun %s:%s: %s\n", taskRun.GetNamespace(), taskRun.GetName(), err.Error()) + } + artifacts["taskRun-"+taskRun.Name+".yaml"] = taskRunYaml + + if err := logs.StoreArtifacts(artifacts); err != nil { + return err + } + + return nil +} + +func (t *TektonController) StoreTaskRunsForPipelineRun(c crclient.Client, pr *pipeline.PipelineRun) error { + for _, chr := range pr.Status.ChildReferences { + taskRun := &pipeline.TaskRun{} + taskRunKey := types.NamespacedName{Namespace: pr.Namespace, Name: chr.Name} + if err := c.Get(context.Background(), taskRunKey, taskRun); err != nil { + return err + } + if err := t.StoreTaskRun(taskRun.Name, taskRun); err != nil{ + g.GinkgoWriter.Printf("failed to store taskRun %s:%s: %s\n", taskRun.GetNamespace(), taskRun.GetName(), err.Error()) + } + } + return nil +} + // GetTaskRunLogs returns logs of a specified taskRun. func (t *TektonController) GetTaskRunLogs(pipelineRunName, pipelineTaskName, namespace string) (map[string]string, error) { tektonClient := t.PipelineClient().TektonV1beta1().PipelineRuns(namespace) diff --git a/tests/release/pipelines/rh_advisories.go b/tests/release/pipelines/rh_advisories.go index f550b091a..e9e369c80 100644 --- a/tests/release/pipelines/rh_advisories.go +++ b/tests/release/pipelines/rh_advisories.go @@ -97,6 +97,9 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-advisories pip if err = managedFw.AsKubeDeveloper.TektonController.StorePipelineRun(pipelineRun.Name, pipelineRun); err != nil { GinkgoWriter.Printf("failed to store PipelineRun %s:%s: %s\n", pipelineRun.GetNamespace(), pipelineRun.GetName(), err.Error()) } + if err = managedFw.AsKubeDeveloper.TektonController.StoreTaskRunsForPipelineRun(managedFw.AsKubeAdmin.CommonController.KubeRest(), pipelineRun); err != nil { + GinkgoWriter.Printf("failed to store TaskRuns for PipelineRun %s:%s: %s\n", pipelineRun.GetNamespace(), pipelineRun.GetName(), err.Error()) + } if err = devFw.AsKubeDeveloper.ReleaseController.StoreRelease(releaseCR); err != nil { GinkgoWriter.Printf("failed to store Release %s:%s: %s\n", releaseCR.GetNamespace(), releaseCR.GetName(), err.Error()) }