From af547b8bf452d24006596959a1bda507ea303acf Mon Sep 17 00:00:00 2001 From: kakj <18579115540@163.com> Date: Fri, 10 Sep 2021 14:21:57 +0800 Subject: [PATCH] Automated test step running uses the last execution record of the current scene to render the ${{ outputs.xxx.xxx }} placeholders in it (#1781) --- modules/dop/services/autotest_v2/scene.go | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/dop/services/autotest_v2/scene.go b/modules/dop/services/autotest_v2/scene.go index 34425e0c32d..96f5019be97 100644 --- a/modules/dop/services/autotest_v2/scene.go +++ b/modules/dop/services/autotest_v2/scene.go @@ -525,6 +525,8 @@ func (svc *Service) ExecuteDiceAutotestSceneStep(req apistructs.AutotestExecuteS apiTestStr = strings.ReplaceAll(apiTestStr, expression.OldLeftPlaceholder+expression.Params+"."+param.Name+expression.OldRightPlaceholder, expression.ReplaceRandomParams(param.Temp)) } + apiTestStr = svc.renderPreSceneStepsOutput(step.SceneID, apiTestStr) + for _, conf := range configs.Data { switch conf.Key { case autotest.CmsCfgKeyAPIGlobalConfig: @@ -596,6 +598,50 @@ func (svc *Service) ExecuteDiceAutotestSceneStep(req apistructs.AutotestExecuteS return &respData, nil } +func (svc *Service) renderPreSceneStepsOutput(sceneID uint64, replaceYml string) string { + var pipelinePageListRequest = apistructs.PipelinePageListRequest{ + PageNum: 1, + PageSize: 1, + Sources: []apistructs.PipelineSource{ + apistructs.PipelineSourceAutoTest, + }, + YmlNames: []string{ + strconv.Itoa(int(sceneID)), + }, + Statuses: []string{apistructs.PipelineStatusSuccess.String(), apistructs.PipelineStatusFailed.String()}, + DescCols: []string{"id"}, + } + pagePipeline, err := svc.bdl.PageListPipeline(pipelinePageListRequest) + if err != nil { + logrus.Errorf("renderPreSceneStepsOutput, pageListPipeline error %v", err) + return replaceYml + } + + if pagePipeline == nil || len(pagePipeline.Pipelines) <= 0 { + return replaceYml + } + + pipeline, err := svc.bdl.GetPipeline(pagePipeline.Pipelines[0].ID) + if err != nil { + logrus.Errorf("renderPreSceneStepsOutput, GetPipeline error %v", err) + return replaceYml + } + + if pipeline == nil { + return replaceYml + } + + for _, stage := range pipeline.PipelineStages { + for _, task := range stage.PipelineTasks { + for _, result := range task.Result.Metadata { + replaceYml = strings.ReplaceAll(replaceYml, expression.GenOutputRef(task.Name, result.Name), result.Value) + } + } + } + + return replaceYml +} + func (svc *Service) SceneToYml(scene uint64) (string, error) { sceneInputs, err := svc.ListAutoTestSceneInput(scene) if err != nil {