diff --git a/pkg/server/domain/service/pipeline.go b/pkg/server/domain/service/pipeline.go index 7795f470a..b41b9ab4d 100644 --- a/pkg/server/domain/service/pipeline.go +++ b/pkg/server/domain/service/pipeline.go @@ -23,6 +23,7 @@ import ( "fmt" "hash/fnv" "io" + "regexp" "sort" "strings" "sync" @@ -61,6 +62,8 @@ const ( labelPipeline = "pipeline.oam.dev/name" ) +var re = regexp.MustCompile(`"((?:[^"\\]|\\.)*)"`) + // PipelineService is the interface for pipeline service type PipelineService interface { CreatePipeline(ctx context.Context, req apis.CreatePipelineRequest) (*apis.PipelineBase, error) @@ -491,10 +494,23 @@ func (p pipelineRunServiceImpl) GetPipelineRunLog(ctx context.Context, pipelineR var logs string switch { case logConfig.Data: + var id string + for _, s := range pipelineRun.Status.Steps { + if s.Name == step { + id = s.ID + break + } + for _, sub := range s.SubStepsStatus { + if sub.Name == step { + id = sub.ID + break + } + } + } logs, err = getResourceLogs(ctx, p.KubeConfig, p.KubeClient, []wfTypes.Resource{{ Namespace: velatypes.DefaultKubeVelaNS, LabelSelector: map[string]string{"app.kubernetes.io/name": "vela-workflow"}, - }}, []string{fmt.Sprintf(`step_name="%s"`, step), fmt.Sprintf("%s/%s", project.GetNamespace(), pipelineRun.PipelineRunName), "cue logs"}) + }}, []string{fmt.Sprintf(`stepSessionID="%s"`, id), fmt.Sprintf("%s/%s", project.GetNamespace(), pipelineRun.PipelineRunName), "cue logs"}) if err != nil { return apis.GetPipelineRunLogResponse{}, err } @@ -684,6 +700,10 @@ func getResourceLogs(ctx context.Context, config *rest.Config, cli client.Client } } if shouldPrint { + match := re.FindStringSubmatch(s) + if len(match) > 1 { + s = strings.ReplaceAll(match[1], "\\n", "\n") + } buf.WriteString(s) } }