diff --git a/pkg/client/devops/fake/fakedevops.go b/pkg/client/devops/fake/fakedevops.go index 23468241..38c43bf2 100644 --- a/pkg/client/devops/fake/fakedevops.go +++ b/pkg/client/devops/fake/fakedevops.go @@ -198,8 +198,8 @@ func (d *Devops) DownloadArtifact(projectName, pipelineName, runId, filename str return nil, nil } -func (d *Devops) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) { - return nil, nil +func (d *Devops) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) { + return nil, nil, nil } func (d *Devops) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) { return nil, nil, nil diff --git a/pkg/client/devops/fake/fakedevops_test.go b/pkg/client/devops/fake/fakedevops_test.go index 2fe48543..375a3396 100644 --- a/pkg/client/devops/fake/fakedevops_test.go +++ b/pkg/client/devops/fake/fakedevops_test.go @@ -193,8 +193,8 @@ func TestNotImplement(t *testing.T) { assertNils(t, o1, o2) o1, o2 = client.DownloadArtifact("", "", "", "", false, "") assertNils(t, o1, o2) - o1, o2 = client.GetRunLog("", "", "", nil) - assertNils(t, o1, o2) + o1, o2, o3 = client.GetRunLog("", "", "", nil) + assertNils(t, o1, o2, o3) o1, o2, o3 = client.GetStepLog("", "", "", "", "", nil) assertNils(t, o1, o2, o3) o1, o2 = client.RunPipeline("", "", nil) diff --git a/pkg/client/devops/jclient/pipeline.go b/pkg/client/devops/jclient/pipeline.go index 818414f6..6adec7bf 100644 --- a/pkg/client/devops/jclient/pipeline.go +++ b/pkg/client/devops/jclient/pipeline.go @@ -81,7 +81,7 @@ func (j *JenkinsClient) DownloadArtifact(projectName, pipelineName, runID, filen } // GetRunLog returns the log output of a pipeline run -func (j *JenkinsClient) GetRunLog(projectName, pipelineName, runID string, httpParameters *devops.HttpParameters) ([]byte, error) { +func (j *JenkinsClient) GetRunLog(projectName, pipelineName, runID string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) { return j.jenkins.GetRunLog(projectName, pipelineName, runID, httpParameters) } diff --git a/pkg/client/devops/jenkins/jenkins.go b/pkg/client/devops/jenkins/jenkins.go index b1d0f0e9..3e9a08f0 100644 --- a/pkg/client/devops/jenkins/jenkins.go +++ b/pkg/client/devops/jenkins/jenkins.go @@ -308,14 +308,13 @@ func (j *Jenkins) GetArtifacts(projectName, pipelineName, runId string, httpPara return res, err } -func (j *Jenkins) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, error) { +func (j *Jenkins) GetRunLog(projectName, pipelineName, runId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) { PipelineOjb := &Pipeline{ HttpParameters: httpParameters, Jenkins: j, Path: fmt.Sprintf(GetRunLogUrl+httpParameters.Url.RawQuery, projectName, pipelineName, runId), } - res, err := PipelineOjb.GetRunLog() - return res, err + return PipelineOjb.GetRunLog() } func (j *Jenkins) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *devops.HttpParameters) ([]byte, http.Header, error) { diff --git a/pkg/client/devops/jenkins/pipeline.go b/pkg/client/devops/jenkins/pipeline.go index e43706f4..51455809 100644 --- a/pkg/client/devops/jenkins/pipeline.go +++ b/pkg/client/devops/jenkins/pipeline.go @@ -374,13 +374,13 @@ func (p *Pipeline) GetArtifacts() ([]devops.Artifacts, error) { return artifacts, err } -func (p *Pipeline) GetRunLog() ([]byte, error) { - res, err := p.Jenkins.SendPureRequest(p.Path, p.HttpParameters) +func (p *Pipeline) GetRunLog() ([]byte, http.Header, error) { + res, header, err := p.Jenkins.SendPureRequestWithHeaderResp(p.Path, p.HttpParameters) if err != nil { klog.Error(err) } - return res, err + return res, header, err } func (p *Pipeline) GetStepLog() ([]byte, http.Header, error) { diff --git a/pkg/client/devops/pipeline.go b/pkg/client/devops/pipeline.go index 8ba23ae9..8c93d5c0 100644 --- a/pkg/client/devops/pipeline.go +++ b/pkg/client/devops/pipeline.go @@ -1137,7 +1137,7 @@ type PipelineOperator interface { RunPipeline(projectName, pipelineName string, httpParameters *HttpParameters) (*RunPipeline, error) GetArtifacts(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]Artifacts, error) DownloadArtifact(projectName, pipelineName, runId, filename string, isMultiBranch bool, branchName string) (io.ReadCloser, error) - GetRunLog(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]byte, error) + GetRunLog(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]byte, http.Header, error) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, httpParameters *HttpParameters) ([]byte, http.Header, error) GetNodeSteps(projectName, pipelineName, runId, nodeId string, httpParameters *HttpParameters) ([]NodeSteps, error) GetPipelineRunNodes(projectName, pipelineName, runId string, httpParameters *HttpParameters) ([]PipelineRunNodes, error) diff --git a/pkg/kapis/devops/v1alpha2/devops.go b/pkg/kapis/devops/v1alpha2/devops.go index 523dcb39..584a0fc7 100644 --- a/pkg/kapis/devops/v1alpha2/devops.go +++ b/pkg/kapis/devops/v1alpha2/devops.go @@ -278,12 +278,18 @@ func (h *ProjectPipelineHandler) GetRunLog(req *restful.Request, resp *restful.R pipelineName := req.PathParameter("pipeline") runId := req.PathParameter("run") - res, err := h.devopsOperator.GetRunLog(projectName, pipelineName, runId, req.Request) + res, header, err := h.devopsOperator.GetRunLog(projectName, pipelineName, runId, req.Request) if err != nil { parseErr(err, resp) return } + for k, v := range header { + if strings.HasPrefix(k, jenkinsHeaderPre) { + resp.AddHeader(k, v[0]) + } + } + resp.Write(res) } diff --git a/pkg/models/devops/devops.go b/pkg/models/devops/devops.go index 19a84085..bf684c85 100644 --- a/pkg/models/devops/devops.go +++ b/pkg/models/devops/devops.go @@ -83,7 +83,7 @@ type DevopsOperator interface { ReplayPipeline(projectName, pipelineName, runId string, req *http.Request) (*devops.ReplayPipeline, error) RunPipeline(projectName, pipelineName string, req *http.Request) (*devops.RunPipeline, error) GetArtifacts(projectName, pipelineName, runId string, req *http.Request) ([]devops.Artifacts, error) - GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) + GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, http.Header, error) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, http.Header, error) GetNodeSteps(projectName, pipelineName, runId, nodeId string, req *http.Request) ([]devops.NodeSteps, error) GetPipelineRunNodes(projectName, pipelineName, runId string, req *http.Request) ([]devops.PipelineRunNodes, error) @@ -550,15 +550,15 @@ func (d devopsOperator) GetArtifacts(projectName, pipelineName, runId string, re return res, err } -func (d devopsOperator) GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, error) { +func (d devopsOperator) GetRunLog(projectName, pipelineName, runId string, req *http.Request) ([]byte, http.Header, error) { - res, err := d.devopsClient.GetRunLog(projectName, pipelineName, runId, convertToHttpParameters(req)) + res, header, err := d.devopsClient.GetRunLog(projectName, pipelineName, runId, convertToHttpParameters(req)) if err != nil { klog.Error(err) - return nil, err + return nil, nil, err } - return res, err + return res, header, err } func (d devopsOperator) GetStepLog(projectName, pipelineName, runId, nodeId, stepId string, req *http.Request) ([]byte, http.Header, error) {