From 7418f2bfab7a7a004ae72acc52908e4f73abc959 Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Wed, 11 Oct 2023 17:31:04 +0530 Subject: [PATCH 1/3] check for active ci_pipeline_material --- internal/sql/repository/pipelineConfig/CiPipelineRepository.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go index 974d1b7b6e8..fccf0f5166f 100644 --- a/internal/sql/repository/pipelineConfig/CiPipelineRepository.go +++ b/internal/sql/repository/pipelineConfig/CiPipelineRepository.go @@ -285,6 +285,9 @@ func (impl CiPipelineRepositoryImpl) FindById(id int) (pipeline *CiPipeline, err pipeline = &CiPipeline{Id: id} err = impl.dbConnection.Model(pipeline). Column("ci_pipeline.*", "App", "CiPipelineMaterials", "CiTemplate", "CiTemplate.DockerRegistry", "CiPipelineMaterials.GitMaterial"). + Relation("CiPipelineMaterials", func(q *orm.Query) (query *orm.Query, err error) { + return q.Where("(ci_pipeline_material.active=true)"), nil + }). Where("ci_pipeline.id= ?", id). Where("ci_pipeline.deleted =? ", false). Select() From d422120423027fc936f727f308e166cf312ef6bb Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Tue, 17 Oct 2023 22:17:35 +0530 Subject: [PATCH 2/3] check for len of steps --- pkg/pipeline/CiCdPipelineOrchestrator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index f7a34847089..b31a4f95281 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -1543,7 +1543,7 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateCDPipeline(pipelineRequest *bean. } } - if pipelineRequest.PreDeployStage != nil { + if pipelineRequest.PreDeployStage != nil && len(pipelineRequest.PreDeployStage.Steps) > 0 { //updating pre stage err = impl.pipelineStageService.UpdatePipelineStage(pipelineRequest.PreDeployStage, repository5.PIPELINE_STAGE_TYPE_PRE_CD, pipelineRequest.Id, userId) if err != nil { @@ -1551,7 +1551,7 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateCDPipeline(pipelineRequest *bean. return err } } - if pipelineRequest.PostDeployStage != nil { + if pipelineRequest.PostDeployStage != nil && len(pipelineRequest.PostDeployStage.Steps) > 0 { //updating post stage err = impl.pipelineStageService.UpdatePipelineStage(pipelineRequest.PostDeployStage, repository5.PIPELINE_STAGE_TYPE_POST_CD, pipelineRequest.Id, userId) if err != nil { From f4cf99011a1743d599c653495f293a0965118ccd Mon Sep 17 00:00:00 2001 From: Ashish-devtron Date: Tue, 17 Oct 2023 23:13:56 +0530 Subject: [PATCH 3/3] check for len of steps --- pkg/pipeline/CiCdPipelineOrchestrator.go | 4 ++-- pkg/pipeline/PipelineStageService.go | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/pipeline/CiCdPipelineOrchestrator.go b/pkg/pipeline/CiCdPipelineOrchestrator.go index b31a4f95281..f7a34847089 100644 --- a/pkg/pipeline/CiCdPipelineOrchestrator.go +++ b/pkg/pipeline/CiCdPipelineOrchestrator.go @@ -1543,7 +1543,7 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateCDPipeline(pipelineRequest *bean. } } - if pipelineRequest.PreDeployStage != nil && len(pipelineRequest.PreDeployStage.Steps) > 0 { + if pipelineRequest.PreDeployStage != nil { //updating pre stage err = impl.pipelineStageService.UpdatePipelineStage(pipelineRequest.PreDeployStage, repository5.PIPELINE_STAGE_TYPE_PRE_CD, pipelineRequest.Id, userId) if err != nil { @@ -1551,7 +1551,7 @@ func (impl CiCdPipelineOrchestratorImpl) UpdateCDPipeline(pipelineRequest *bean. return err } } - if pipelineRequest.PostDeployStage != nil && len(pipelineRequest.PostDeployStage.Steps) > 0 { + if pipelineRequest.PostDeployStage != nil { //updating post stage err = impl.pipelineStageService.UpdatePipelineStage(pipelineRequest.PostDeployStage, repository5.PIPELINE_STAGE_TYPE_POST_CD, pipelineRequest.Id, userId) if err != nil { diff --git a/pkg/pipeline/PipelineStageService.go b/pkg/pipeline/PipelineStageService.go index 56ae6d9ef3c..45bb1b91626 100644 --- a/pkg/pipeline/PipelineStageService.go +++ b/pkg/pipeline/PipelineStageService.go @@ -964,10 +964,12 @@ func (impl *PipelineStageServiceImpl) UpdatePipelineStage(stageReq *bean.Pipelin if err == pg.ErrNoRows || createNewPipStage { //no stage found, creating new stage stageReq.Id = 0 - err = impl.CreatePipelineStage(stageReq, stageType, pipelineId, userId) - if err != nil { - impl.logger.Errorw("error in creating new pipeline stage", "err", err, "pipelineStageReq", stageReq) - return err + if len(stageReq.Steps) > 0 { + err = impl.CreatePipelineStage(stageReq, stageType, pipelineId, userId) + if err != nil { + impl.logger.Errorw("error in creating new pipeline stage", "err", err, "pipelineStageReq", stageReq) + return err + } } } else { //stageId found, to handle as an update request