From 4bb931d6f8d7b177862ca030cf44af22ce632d9c Mon Sep 17 00:00:00 2001 From: Asutosh Das Date: Mon, 27 Nov 2023 17:40:07 +0530 Subject: [PATCH] fix: Get Artifacts list API is throwing pg no rows error (#4292) * fixed: get artifacts list API is throwing pg no rows error * handling for job ci --- .../sql/repository/CiArtifactsListingQueryBuilder.go | 2 +- pkg/dockerRegistry/DockerRegistryIpsConfigService.go | 2 +- pkg/pipeline/AppArtifactManager.go | 12 ++++++------ pkg/pipeline/CiService.go | 5 ++++- pkg/pipeline/WebhookService.go | 8 +++++++- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/internal/sql/repository/CiArtifactsListingQueryBuilder.go b/internal/sql/repository/CiArtifactsListingQueryBuilder.go index a7ff12332c2..29220239f41 100644 --- a/internal/sql/repository/CiArtifactsListingQueryBuilder.go +++ b/internal/sql/repository/CiArtifactsListingQueryBuilder.go @@ -17,7 +17,7 @@ func BuildQueryForParentTypeCIOrWebhook(listingFilterOpts bean.ArtifactsListFilt selectQuery := " SELECT cia.* " remainingQuery := " FROM ci_artifact cia" + " INNER JOIN ci_pipeline cp ON (cp.id=cia.pipeline_id or (cp.id=cia.component_id and cia.data_source='post_ci' ) )" + - " INNER JOIN pipeline p ON p.ci_pipeline_id = cp.id and p.id=%v" + + " INNER JOIN pipeline p ON (p.ci_pipeline_id = cp.id and p.id=%v )" + " WHERE " remainingQuery = fmt.Sprintf(remainingQuery, listingFilterOpts.PipelineId) if len(listingFilterOpts.ExcludeArtifactIds) > 0 { diff --git a/pkg/dockerRegistry/DockerRegistryIpsConfigService.go b/pkg/dockerRegistry/DockerRegistryIpsConfigService.go index 7e012c0cc35..fe427d61939 100644 --- a/pkg/dockerRegistry/DockerRegistryIpsConfigService.go +++ b/pkg/dockerRegistry/DockerRegistryIpsConfigService.go @@ -161,7 +161,7 @@ func (impl DockerRegistryIpsConfigServiceImpl) getDockerRegistryIdForCiPipeline( if artifact.CredentialsSourceType == repository3.GLOBAL_CONTAINER_REGISTRY { dockerRegistryId = artifact.CredentialSourceValue } - } else { + } else if artifact.DataSource == repository3.CI_RUNNER { // if image is created by ci build dockerRegistryId = *ciPipeline.CiTemplate.DockerRegistryId if len(dockerRegistryId) == 0 { diff --git a/pkg/pipeline/AppArtifactManager.go b/pkg/pipeline/AppArtifactManager.go index 88eb0842a74..39835ec00ed 100644 --- a/pkg/pipeline/AppArtifactManager.go +++ b/pkg/pipeline/AppArtifactManager.go @@ -623,12 +623,12 @@ func (impl *AppArtifactManagerImpl) RetrieveArtifactsByCDPipelineV2(pipeline *pi sort.SliceStable(ciArtifacts, func(i, j int) bool { return ciArtifacts[i].Id > ciArtifacts[j].Id }) - } - ciArtifacts, err = impl.setAdditionalDataInArtifacts(ciArtifacts, pipeline) - if err != nil { - impl.logger.Errorw("error in setting additional data in fetched artifacts", "pipelineId", pipeline.Id, "err", err) - return ciArtifactsResponse, err + ciArtifacts, err = impl.setAdditionalDataInArtifacts(ciArtifacts, pipeline) + if err != nil { + impl.logger.Errorw("error in setting additional data in fetched artifacts", "pipelineId", pipeline.Id, "err", err) + return ciArtifactsResponse, err + } } ciArtifactsResponse.CdPipelineId = pipeline.Id @@ -673,7 +673,7 @@ func (impl *AppArtifactManagerImpl) setAdditionalDataInArtifacts(ciArtifacts []b if ciArtifacts[i].CredentialsSourceType == repository.GLOBAL_CONTAINER_REGISTRY { dockerRegistryId = ciArtifacts[i].CredentialsSourceValue } - } else { + } else if ciArtifacts[i].DataSource == repository.CI_RUNNER { ciPipeline, err := impl.CiPipelineRepository.FindById(ciArtifacts[i].CiPipelineId) if err != nil { impl.logger.Errorw("error in fetching ciPipeline", "ciPipelineId", ciPipeline.Id, "error", err) diff --git a/pkg/pipeline/CiService.go b/pkg/pipeline/CiService.go index 014e0b76ce4..ebb068ef16a 100644 --- a/pkg/pipeline/CiService.go +++ b/pkg/pipeline/CiService.go @@ -481,7 +481,10 @@ func (impl *CiServiceImpl) buildWfRequestForCiPipeline(pipeline *pipelineConfig. } savedWf.ImagePathReservationIds = []int{imagePathReservation.Id} //imagePath = docker.io/avd0/dashboard:fd23414b - dockerImageTag = strings.Split(imagePathReservation.ImagePath, ":")[1] + imagePathSplit := strings.Split(imagePathReservation.ImagePath, ":") + if len(imagePathSplit) >= 1 { + dockerImageTag = imagePathSplit[len(imagePathSplit)-1] + } } else { dockerImageTag = impl.buildImageTag(commitHashes, pipeline.Id, savedWf.Id) } diff --git a/pkg/pipeline/WebhookService.go b/pkg/pipeline/WebhookService.go index 23f97c12c5f..b4beb14131a 100644 --- a/pkg/pipeline/WebhookService.go +++ b/pkg/pipeline/WebhookService.go @@ -213,7 +213,10 @@ func (impl WebhookServiceImpl) HandleCiSuccessEvent(ciPipelineId int, request *C if !imagePushedAt.IsZero() { createdOn = *imagePushedAt } - + if pipeline.PipelineType == bean.CI_JOB && request.Image == "" { + impl.logger.Errorw("empty image artifact found!", "request", request) + return 0, fmt.Errorf("empty image artifact found") + } buildArtifact := &repository.CiArtifact{ Image: request.Image, ImageDigest: request.ImageDigest, @@ -248,6 +251,9 @@ func (impl WebhookServiceImpl) HandleCiSuccessEvent(ciPipelineId int, request *C var pluginArtifacts []*repository.CiArtifact for registry, artifacts := range request.PluginRegistryArtifactDetails { for _, image := range artifacts { + if pipeline.PipelineType == bean.CI_JOB && image == "" { + continue + } pluginArtifact := &repository.CiArtifact{ Image: image, ImageDigest: request.ImageDigest,